/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "../libssts/SimpleTypeSystem.h"
#include "test_macros.h"
#include "base_n.h"


const schar * testdata1 = "Hello World!";
const schar * testdata2 = "Hello World";
const schar * testdata3 = "Hello LibSSTS!";
const schar * testdata4 = "";

int
test_base_16_text (void) {
  setup_unit ();
  
  size_t testdata_size = strlen (testdata1),
         out_size = 0,
         hex_size = 0,
         out2_size = 0;
  
  schar * hex = s_base_16_enc ((sbyte *) testdata1, testdata_size, &out_size);
  
  //s_print ("HEX: %s\n", hex);
  
  test_case (s_string_is_equal ("48656C6C6F20576F726C6421", hex), "The Base16 data has the expected value.");
  
  hex_size = strlen (hex);
  
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
  
  schar * ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
  
  //s_print ("Test data: %s, The output from the decoding: %s\n", testdata1, ret);
  
  test_case (s_string_is_equal (testdata1, ret), "The string has the expected value");
  
  s_free (hex);
  s_free (ret);
  
  //////////////////////////////////////////////////////////////////////////////
  
  testdata_size = strlen (testdata2);
  
  hex = s_base_16_enc ((sbyte *) testdata2, testdata_size, &out_size);
  
  test_case (s_string_is_equal ("48656C6C6F20576F726C64", hex), "The Base16 data has the expected value.");
  
  //s_print ("HEX: %s\n", hex);
  
  hex_size = strlen (hex);
  
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
  
  ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
  
  test_case (s_string_is_equal (testdata2, ret), "The string has the expected value");
  
  s_free (hex);
  s_free (ret);
  
  //////////////////////////////////////////////////////////////////////////////
  
  testdata_size = strlen (testdata4);
  
  hex = s_base_16_enc ((sbyte *) testdata4, testdata_size, &out_size);
  
  test_case (s_string_is_equal ("", hex), "The Base16 data has the expected value.");
  
  s_print ("HEX: %s\n", hex);
  
  hex_size = strlen (hex);
  
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
  
  ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
  
  s_print ("RET:%s\n", ret);
  
  test_case (s_string_is_equal (testdata4, ret), "The string has the expected value");
  
  s_free (hex);
  s_free (ret);
  
  end_unit ();
}

typedef struct TestBase16Struct {
  sint some_value;
  slong some_other_value;
} TestBase16Struct;

int
test_base_16_object (void) {
  setup_unit ();
  
  TestBase16Struct * t1 = s_malloc (sizeof (TestBase16Struct));
  t1->some_value = 1337;
  t1->some_other_value = 7331;
  
  size_t testdata_size = sizeof (TestBase16Struct),
         out_size,
         out2_size;
  
  schar * t_hex = s_base_16_enc ((sbyte *) t1, testdata_size, &out_size);
  
  //s_print ("%s\n", t_hex);
  
  TestBase16Struct * t2 = (TestBase16Struct *) s_base_16_dec (t_hex, out_size, &out2_size);
  
  //s_print ("TestBase16Struct: some_value: %i, some_other_value: %li\n", t2->some_value, t2->some_other_value);
  
  test_case (t2->some_value == t1->some_value, "some_value are equal.");
  test_case (t2->some_other_value == t1->some_other_value, "some_other_value are equal");
  
  free (t_hex);
  free (t1);
  free (t2);
  
  end_unit ();
}


const schar * testdata3_base_32 = "JBSWY3DPEBGGSYSTKNKFGII=";

int
test_base_32_text (void) {
  setup_unit ();
  
  end_unit ();
}