#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 ();
}
