/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to tests/base_n.c

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-19 19:46:23 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210119194623-7dg2a4wdjjd90ojc
Base16[enc,dec] - Can now create byte arrays of fixed size.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
const schar * testdata2 = "Hello World";
8
8
 
9
9
int
10
 
test_base_n (void) {
 
10
test_base_16_text (void) {
11
11
  setup_unit ();
12
12
  
13
13
  size_t testdata_size = strlen (testdata1),
17
17
  
18
18
  schar * hex = s_base_16_enc ((sbyte *) testdata1, testdata_size, &out_size);
19
19
  
20
 
  s_print ("HEX: %s\n", hex);
 
20
  //s_print ("HEX: %s\n", hex);
21
21
  
22
22
  test_case (s_string_is_equal ("48656C6C6F20576F726C6421", hex), "The Base16 data has the expected value.");
23
23
  
27
27
  
28
28
  schar * ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
29
29
  
30
 
  s_print ("Test data: %s, The output from the decoding: %s\n", testdata1, ret);
 
30
  //s_print ("Test data: %s, The output from the decoding: %s\n", testdata1, ret);
31
31
  
32
32
  test_case (s_string_is_equal (testdata1, ret), "The string has the expected value");
33
33
  
34
34
  s_free (hex);
35
35
  s_free (ret);
36
36
  
 
37
  //////////////////////////////////////////////////////////////////////////////
 
38
  
37
39
  testdata_size = strlen (testdata2);
38
40
  
39
41
  hex = s_base_16_enc ((sbyte *) testdata2, testdata_size, &out_size);
40
42
  
41
43
  test_case (s_string_is_equal ("48656C6C6F20576F726C64", hex), "The Base16 data has the expected value.");
42
44
  
43
 
  s_print ("HEX: %s\n", hex);
 
45
  //s_print ("HEX: %s\n", hex);
44
46
  
45
47
  hex_size = strlen (hex);
46
48
  
47
49
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
48
50
  
 
51
  ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
 
52
  
 
53
  test_case (s_string_is_equal (testdata2, ret), "The string has the expected value");
 
54
  
 
55
  s_free (hex);
 
56
  
 
57
  end_unit ();
 
58
}
 
59
 
 
60
typedef struct TestBase16Struct {
 
61
  sint some_value;
 
62
  slong some_other_value;
 
63
} TestBase16Struct;
 
64
 
 
65
int
 
66
test_base_16_object (void) {
 
67
  setup_unit ();
 
68
  
 
69
  TestBase16Struct * t1 = s_malloc (sizeof (TestBase16Struct));
 
70
  t1->some_value = 1337;
 
71
  t1->some_other_value = 7331;
 
72
  
 
73
  size_t testdata_size = sizeof (TestBase16Struct),
 
74
         out_size,
 
75
         out2_size;
 
76
  
 
77
  schar * t_hex = s_base_16_enc ((sbyte *) t1, testdata_size, &out_size);
 
78
  
 
79
  s_print ("%s\n", t_hex);
 
80
  
 
81
  TestBase16Struct * t2 = (TestBase16Struct *) s_base_16_dec (t_hex, out_size, &out2_size);
 
82
  
 
83
  s_print ("TestBase16Struct: some_value: %i, some_other_value: %li\n", t2->some_value, t2->some_other_value);
 
84
  
 
85
  test_case (t2->some_value == t1->some_value, "some_value are equal.");
 
86
  test_case (t2->some_other_value == t1->some_other_value, "some_other_value are equal");
 
87
  
 
88
  free (t_hex);
 
89
  free (t1);
 
90
  free (t2);
 
91
  
49
92
  end_unit ();
50
93
}