/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 18:52:52 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210119185252-yz4p8rthcr4uv4f5
Fixed Base16 encoding and decoding

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include "base_n.h"
4
4
 
5
5
 
6
 
const schar * testdata = "Hello World!";
 
6
const schar * testdata1 = "Hello World!";
 
7
const schar * testdata2 = "Hello World";
7
8
 
8
9
int
9
10
test_base_n (void) {
10
11
  setup_unit ();
11
12
  
12
 
  size_t testdata_size = strlen (testdata),
 
13
  size_t testdata_size = strlen (testdata1),
13
14
         out_size = 0,
14
15
         hex_size = 0,
15
16
         out2_size = 0;
16
17
  
17
 
  schar * hex = s_base_16_enc ((sbyte *) testdata, testdata_size, &out_size);
 
18
  schar * hex = s_base_16_enc ((sbyte *) testdata1, testdata_size, &out_size);
18
19
  
19
20
  s_print ("HEX: %s\n", hex);
20
21
  
21
 
  test_case (s_string_is_equal ("48656C6C6F20576F726C642100", hex), "The Base16 data has the expected value.");
 
22
  test_case (s_string_is_equal ("48656C6C6F20576F726C6421", hex), "The Base16 data has the expected value.");
22
23
  
23
24
  hex_size = strlen (hex);
24
25
  
 
26
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
 
27
  
25
28
  schar * ret = (schar *) s_base_16_dec (hex, hex_size, &out2_size);
26
29
  
27
 
  s_print ("Test data: %s, The output from the decoding: %s\n", testdata, ret);
28
 
  
29
 
  test_case (s_string_is_equal (testdata, ret), "The string has the expected value");
30
 
  
 
30
  s_print ("Test data: %s, The output from the decoding: %s\n", testdata1, ret);
 
31
  
 
32
  test_case (s_string_is_equal (testdata1, ret), "The string has the expected value");
31
33
  
32
34
  s_free (hex);
33
35
  s_free (ret);
34
36
  
 
37
  testdata_size = strlen (testdata2);
 
38
  
 
39
  hex = s_base_16_enc ((sbyte *) testdata2, testdata_size, &out_size);
 
40
  
 
41
  test_case (s_string_is_equal ("48656C6C6F20576F726C64", hex), "The Base16 data has the expected value.");
 
42
  
 
43
  s_print ("HEX: %s\n", hex);
 
44
  
 
45
  hex_size = strlen (hex);
 
46
  
 
47
  test_case (out_size == hex_size, "The outputed string has the same length as what the function reports.");
 
48
  
35
49
  end_unit ();
36
50
}