/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
1
#include "../libssts/SimpleTypeSystem.h"
2
#include "test_macros.h"
3
#include "base_n.h"
4
5
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
6
const schar * testdata1 = "Hello World!";
7
const schar * testdata2 = "Hello World";
162 by Gustav Hartvigsson
* stuff to do with the unfinished base32 implementation.
8
const schar * testdata3 = "Hello LibSSTS!";
9
const schar * testdata4 = "";
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
10
11
int
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
12
test_base_16_text (void) {
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
13
  setup_unit ();
14
  
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
15
  size_t testdata_size = strlen (testdata1),
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
16
         out_size = 0,
17
         hex_size = 0,
151 by Gustav Hartvigsson
* Fixed all warnings (exept the depricated warning...)
18
         out2_size = 0;
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
19
  
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
20
  schar * hex = s_base_16_enc ((sbyte *) testdata1, testdata_size, &out_size);
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
21
  
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
22
  //s_print ("HEX: %s\n", hex);
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
23
  
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
24
  test_case (s_string_is_equal ("48656C6C6F20576F726C6421", hex), "The Base16 data has the expected value.");
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
25
  
26
  hex_size = strlen (hex);
27
  
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
28
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
29
  
151 by Gustav Hartvigsson
* Fixed all warnings (exept the depricated warning...)
30
  schar * ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
31
  
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
32
  //s_print ("Test data: %s, The output from the decoding: %s\n", testdata1, ret);
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
33
  
34
  test_case (s_string_is_equal (testdata1, ret), "The string has the expected value");
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
35
  
36
  s_free (hex);
37
  s_free (ret);
38
  
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
39
  //////////////////////////////////////////////////////////////////////////////
40
  
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
41
  testdata_size = strlen (testdata2);
42
  
43
  hex = s_base_16_enc ((sbyte *) testdata2, testdata_size, &out_size);
44
  
45
  test_case (s_string_is_equal ("48656C6C6F20576F726C64", hex), "The Base16 data has the expected value.");
46
  
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
47
  //s_print ("HEX: %s\n", hex);
160 by Gustav Hartvigsson
Fixed Base16 encoding and decoding
48
  
49
  hex_size = strlen (hex);
50
  
51
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
52
  
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
53
  ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
54
  
55
  test_case (s_string_is_equal (testdata2, ret), "The string has the expected value");
56
  
57
  s_free (hex);
162 by Gustav Hartvigsson
* stuff to do with the unfinished base32 implementation.
58
  s_free (ret);
59
  
60
  //////////////////////////////////////////////////////////////////////////////
61
  
62
  testdata_size = strlen (testdata4);
63
  
64
  hex = s_base_16_enc ((sbyte *) testdata4, testdata_size, &out_size);
65
  
66
  test_case (s_string_is_equal ("", hex), "The Base16 data has the expected value.");
67
  
68
  s_print ("HEX: %s\n", hex);
69
  
70
  hex_size = strlen (hex);
71
  
72
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
73
  
74
  ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
75
  
76
  s_print ("RET:%s\n", ret);
77
  
78
  test_case (s_string_is_equal (testdata4, ret), "The string has the expected value");
79
  
80
  s_free (hex);
81
  s_free (ret);
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
82
  
83
  end_unit ();
84
}
85
86
typedef struct TestBase16Struct {
87
  sint some_value;
88
  slong some_other_value;
89
} TestBase16Struct;
90
91
int
92
test_base_16_object (void) {
93
  setup_unit ();
94
  
95
  TestBase16Struct * t1 = s_malloc (sizeof (TestBase16Struct));
96
  t1->some_value = 1337;
97
  t1->some_other_value = 7331;
98
  
99
  size_t testdata_size = sizeof (TestBase16Struct),
100
         out_size,
101
         out2_size;
102
  
103
  schar * t_hex = s_base_16_enc ((sbyte *) t1, testdata_size, &out_size);
104
  
162 by Gustav Hartvigsson
* stuff to do with the unfinished base32 implementation.
105
  //s_print ("%s\n", t_hex);
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
106
  
107
  TestBase16Struct * t2 = (TestBase16Struct *) s_base_16_dec (t_hex, out_size, &out2_size);
108
  
162 by Gustav Hartvigsson
* stuff to do with the unfinished base32 implementation.
109
  //s_print ("TestBase16Struct: some_value: %i, some_other_value: %li\n", t2->some_value, t2->some_other_value);
161 by Gustav Hartvigsson
Base16[enc,dec] - Can now create byte arrays of fixed size.
110
  
111
  test_case (t2->some_value == t1->some_value, "some_value are equal.");
112
  test_case (t2->some_other_value == t1->some_other_value, "some_other_value are equal");
113
  
114
  free (t_hex);
115
  free (t1);
116
  free (t2);
117
  
138 by Gustav Hartvigsson
* Fixed s_base_16_enc
118
  end_unit ();
119
}
162 by Gustav Hartvigsson
* stuff to do with the unfinished base32 implementation.
120
121
122
const schar * testdata3_base_32 = "JBSWY3DPEBGGSYSTKNKFGII=";
123
124
int
125
test_base_32_text (void) {
126
  setup_unit ();
127
  
128
  end_unit ();
129
}