3 char *key_u32
= "test_u32";
4 char *key_str
= "test_str";
5 char *key_mem
= "test_mem";
6 char *key_label
= "test_label";
8 /*===========================================================================*
10 *===========================================================================*/
16 /* Publish and retrieve. */
17 r
= ds_publish_u32(key_u32
, 1234, 0);
19 r
= ds_retrieve_u32(key_u32
, &value
);
20 assert(r
== OK
&& value
== 1234);
22 /* If dstest deletes 'test_u32' immediately after publishing it,
23 * subs will catch the event, but it can't check it immediately.
24 * So dstest will sleep 2 seconds to wait for subs to complete. */
27 /* Publish again without DSF_OVERWRITE. */
28 r
= ds_publish_u32(key_u32
, 4321, 0);
31 /* Publish again with DSF_OVERWRITE to overwrite it. */
32 r
= ds_publish_u32(key_u32
, 4321, DSF_OVERWRITE
);
34 r
= ds_retrieve_u32(key_u32
, &value
);
35 assert(r
== OK
&& value
== 4321);
38 r
= ds_delete_u32(key_u32
);
40 r
= ds_retrieve_u32(key_u32
, &value
);
43 printf("DSTEST: U32 test successful!\n");
46 /*===========================================================================*
48 *===========================================================================*/
52 char *string
= "little";
53 char *longstring
= "verylooooooongstring";
56 r
= ds_publish_str(key_str
, string
, 0);
59 r
= ds_retrieve_str(key_str
, buf
, sizeof(buf
)-1);
60 assert(r
== OK
&& strcmp(string
, buf
) == 0);
62 r
= ds_delete_str(key_str
);
65 /* Publish a long string. */
66 r
= ds_publish_str(key_str
, longstring
, 0);
69 r
= ds_retrieve_str(key_str
, buf
, sizeof(buf
)-1);
70 assert(r
== OK
&& strcmp(string
, buf
) != 0
71 && strncmp(longstring
, buf
, sizeof(buf
)-1) == 0);
73 r
= ds_delete_str(key_str
);
76 printf("DSTEST: STRING test successful!\n");
79 /*===========================================================================*
81 *===========================================================================*/
84 char *string1
= "ok, this is a string";
85 char *string2
= "ok, this is a very looooong string";
86 size_t len1
= strlen(string1
) + 1;
87 size_t len2
= strlen(string2
) + 1;
92 /* Publish and retrieve. */
93 r
= ds_publish_mem(key_mem
, string1
, len1
, 0);
96 r
= ds_retrieve_mem(key_mem
, buf
, &get_len
);
97 assert(r
== OK
&& strcmp(string1
, buf
) == 0);
98 assert(get_len
== len1
);
100 /* Let get_len=8, which is less than strlen(string1). */
102 r
= ds_retrieve_mem(key_mem
, buf
, &get_len
);
103 assert(r
== OK
&& get_len
== 8);
105 /* Publish again to overwrite with a bigger memory range. */
106 r
= ds_publish_mem(key_mem
, string2
, len2
, DSF_OVERWRITE
);
110 r
= ds_retrieve_mem(key_mem
, buf
, &get_len
);
111 assert(r
== OK
&& strcmp(string2
, buf
) == 0);
112 assert(get_len
== len2
);
114 r
= ds_delete_mem(key_mem
);
117 printf("DSTEST: MEM test successful!\n");
120 /*===========================================================================*
122 *===========================================================================*/
123 void test_label(void)
126 char label
[DS_MAX_KEYLEN
];
129 /* Retrieve own label and endpoint. */
130 r
= ds_retrieve_label_name(label
, sef_self());
132 r
= ds_retrieve_label_endpt(label
, &endpoint
);
133 assert(r
== OK
&& endpoint
== sef_self());
135 /* Publish and delete. */
136 r
= ds_publish_label(label
, endpoint
, 0);
138 r
= ds_delete_label(label
);
141 printf("DSTEST: LABEL test successful!\n");
144 /*===========================================================================*
145 * sef_cb_init_fresh *
146 *===========================================================================*/
147 static int sef_cb_init_fresh(int UNUSED(type
), sef_init_info_t
*UNUSED(info
))
149 /* Run all the tests. */
158 /*===========================================================================*
159 * sef_local_startup *
160 *===========================================================================*/
161 static void sef_local_startup(void)
163 /* Let SEF perform startup. */
164 sef_setcb_init_fresh(sef_cb_init_fresh
);
169 /*===========================================================================*
171 *===========================================================================*/
174 /* SEF local startup. */