/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
#include "SimpleTypeSystem.h"
#include "test_macros.h"
#include <stdlib.h>
#include <stdint.h>
#include <time.h>

void
for_each_print_map (SLinkedList * self, SMapItem * item, sint * itt) {
  s_print ("Key: \"%s\" Value: %d on iteration: %d\n", (schar *)item->key,
                                                       (sint)item->value,
                                                       (*itt));
  (*itt)++;
}

int test_map (void) {
  setup_unit ();
  
  SMap * map = NULL;
  map =  s_map_new (COMPFUNC (s_string_is_equal),
                    HASH_FUNC (s_hash),
                    NULL,
                    NULL);
  
  test_case (map != NULL, "Map is not null.");
  
  s_map_add (map, "Hello", (spointer)(sint) 1337);
  
  test_case ((s_map_get (map, "Hello") == (sint) 1337), "The got value is the"
                                                  " same as the one added to"
                                                  " the map");
  SMapItem * item = s_map_get_item (map, "Hello");
  s_print ("The key was: %s, the Value was: %d\n", (schar *) item->key,
                                                   (sint) item->value);
  
  s_print (S_COLOR_BLUE "Replacing value with a new one\n");
  
  s_map_add (map, "Hello", (spointer)(sint) 1338);
  test_case ((s_map_get (map, "Hello") == (sint) 1338), "The got value is the"
                                                  " same as the one added to"
                                                  " the map");
  
  s_map_free (map, TRUE);
  
  end_unit ();
}