Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bug fix.
[simgrid.git] / src / swag_unit.c
1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
4
5 #include <stdio.h>
6 #include "xbt.h"
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
10
11 # 233 "xbt/swag.c" 
12
13
14 typedef struct {
15   s_xbt_swag_hookup_t setA;
16   s_xbt_swag_hookup_t setB;
17   const char *name;
18 } shmurtz, s_shmurtz_t, *shmurtz_t;
19
20
21 XBT_TEST_UNIT("basic",test_swag_basic,"Basic usage") {
22   shmurtz_t obj1, obj2, obj;
23   xbt_swag_t setA,setB;
24
25   obj1 = calloc(1,sizeof(s_shmurtz_t));
26   obj2 = calloc(1,sizeof(s_shmurtz_t));
27
28   obj1->name="Obj 1";
29   obj2->name="Obj 2";
30
31   xbt_test_add0("Basic usage");
32   xbt_test_log3("%p %p %ld\n",obj1,&(obj1->setB),
33                 (long)((char *)&(obj1->setB) - (char *)obj1));
34
35   setA = xbt_swag_new(xbt_swag_offset(*obj1,setA));
36   setB = xbt_swag_new(xbt_swag_offset(*obj1,setB));
37
38   xbt_swag_insert(obj1, setA);
39   xbt_swag_insert(obj1, setB);
40   xbt_swag_insert(obj2, setA);
41   xbt_swag_insert(obj2, setB);
42
43   xbt_swag_remove(obj1, setB);
44   /*  xbt_swag_remove(obj2, setB);*/
45
46   xbt_test_add0("Traverse set A");
47   xbt_swag_foreach(obj,setA) {
48     xbt_test_log1("Saw: %s",obj->name);
49   }
50
51   xbt_test_add0("Traverse set B");
52   xbt_swag_foreach(obj,setB) {
53     xbt_test_log1("Saw: %s",obj->name);
54   }
55
56   xbt_test_add0("Ensure set content and length");
57   xbt_test_assert(  xbt_swag_belongs(obj1,setA));
58   xbt_test_assert(  xbt_swag_belongs(obj2,setA));
59
60   xbt_test_assert(! xbt_swag_belongs(obj1,setB));
61   xbt_test_assert(  xbt_swag_belongs(obj2,setB));
62
63   xbt_test_assert(xbt_swag_size(setA) == 2);
64   xbt_test_assert(xbt_swag_size(setB) == 1);
65    
66   xbt_swag_free(setA);
67   xbt_swag_free(setB);
68 }
69
70 /*******************************/
71 /* GENERATED FILE, DO NOT EDIT */
72 /*******************************/
73