FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_nomos_gap.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 2014, Siemens AG
3 
4 Author: Steffen Weber, Johannes Najjar
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <CUnit/CUnit.h>
26 #include <stdarg.h>
27 
28 #include "nomos_gap.h"
29 
38 {
39  char* buf, *fer;
40  GArray* po;
41  buf=g_strdup_printf("\377abc\377\377de\377\377fg\377hi");
42  fer=g_strdup(buf);
43 
44  po=collapseInvisible(buf,(char)'\377');
45  for(int i=0; i<po->len; ++i) {
46  pairPosOff* thePoA = getPairPosOff(po, i);
47  CU_ASSERT_EQUAL(*(buf+thePoA->pos), *(fer+thePoA->pos+thePoA->off));
48  }
49  g_array_free(po,TRUE);
50  g_free(buf);
51  g_free(fer);
52 }
53 
62 {
63  char* buf, *fer;
64  GArray* po;
65  buf=g_strdup_printf("\377abc\377\377de\377\377fg\377hi");
66  fer=g_strdup(buf);
67  po=collapseInvisible(buf,(char)'\377' );
68 
69  for(int i=0; i< strlen(buf); i++){
70  CU_ASSERT_EQUAL( *(buf+i) , *(fer + uncollapsePosition(i,po)) );
71  }
72  g_array_free(po,TRUE);
73  g_free(buf);
74  g_free(fer);
75 }
76 
85 {
86  char* buf, *fer;
87  GArray* po;
88  buf=g_strdup_printf(" abc d e fghi");
89  fer=g_strdup(buf);
90  po = collapseSpaces(buf);
91  for(int i=0; i<po->len; ++i) {
92  pairPosOff* thePoA = getPairPosOff(po, i);
93  CU_ASSERT_EQUAL(*(buf+thePoA->pos), *(fer+thePoA->pos+thePoA->off));
94  }
95  g_array_free(po,TRUE);
96  g_free(buf);
97  g_free(fer);
98 }
99 
108 {
109  char* buf, *fer;
110  GArray* po;
111  buf=g_strdup_printf(" abc d e fghi");
112  fer=g_strdup(buf);
113  po = collapseSpaces(buf);
114  for(int i=0; i< strlen(buf); i++){
115  CU_ASSERT_EQUAL( *(buf+i) , *(fer + uncollapsePosition(i,po)) );
116  }
117  g_array_free(po,TRUE);
118  g_free(buf);
119  g_free(fer);
120 }
121 
122 CU_TestInfo nomos_gap_testcases[] = {
123  {"Testing collapse space:", test_collapseSpaces},
124  {"Testing uncollapse space:", test_uncollapseSpaces},
125  {"Testing collapse:", test_collapseInvisible},
126  {"Testing uncollapse:", test_uncollapseInvisible},
127  CU_TEST_INFO_NULL
128 };
GArray * collapseInvisible(char *text, char invisible)
Definition: nomos_gap.c:30
void test_collapseSpaces()
Test for collapseSpaces()
void test_uncollapseInvisible()
Test for uncollapsePosition() on collapseInvisible()
void test_uncollapseSpaces()
Test for uncollapsePosition() on collapseSpaces()
void test_collapseInvisible()
Test for collapseInvisible()
GArray * collapseSpaces(char *text)
Definition: nomos_gap.c:62