return 1;
}
+static int ConfGetChildValueWithDefaultTest(void)
+{
+ char *val;
+ int ret = 1;
+ ConfCreateContextBackup();
+ ConfInit();
+ ConfSet("af-packet.0.interface", "eth0", 1);
+ ConfSet("af-packet.1.interface", "default", 1);
+ ConfSet("af-packet.1.cluster-type", "cluster_cpu", 1);
+
+ ConfNode *root = ConfGetNode("af-packet.0");
+ ConfNode *dflt = ConfGetNode("af-packet.1");
+ ConfGetChildValueWithDefault(root, dflt, "cluster-type", &val);
+ if (strcmp(val, "cluster_cpu")) {
+ ConfDeInit();
+ ConfRestoreContextBackup();
+ return 0;
+ }
+
+ ConfSet("af-packet.0.cluster-type", "cluster_flow", 1);
+ ConfGetChildValueWithDefault(root, dflt, "cluster-type", &val);
+
+ if (strcmp(val, "cluster_flow")) {
+ ret = 0;
+ }
+ ConfDeInit();
+ ConfRestoreContextBackup();
+ return ret;
+}
+
+static int ConfGetChildValueIntWithDefaultTest(void)
+{
+ intmax_t val;
+ ConfCreateContextBackup();
+ ConfInit();
+ ConfSet("af-packet.0.interface", "eth0", 1);
+ ConfSet("af-packet.1.interface", "default", 1);
+ ConfSet("af-packet.1.threads", "2", 1);
+
+ ConfNode *root = ConfGetNode("af-packet.0");
+ ConfNode *dflt = ConfGetNode("af-packet.1");
+ ConfGetChildValueIntWithDefault(root, dflt, "threads", &val);
+ if (val != 2) {
+ ConfDeInit();
+ ConfRestoreContextBackup();
+ return 0;
+ }
+
+ ConfSet("af-packet.0.threads", "1", 1);
+ ConfGetChildValueIntWithDefault(root, dflt, "threads", &val);
+
+ ConfDeInit();
+ ConfRestoreContextBackup();
+ if (val != 1) {
+ return 0;
+ }
+ return 1;
+}
+
+static int ConfGetChildValueBoolWithDefaultTest(void)
+{
+ int val;
+ ConfCreateContextBackup();
+ ConfInit();
+ ConfSet("af-packet.0.interface", "eth0", 1);
+ ConfSet("af-packet.1.interface", "default", 1);
+ ConfSet("af-packet.1.use-mmap", "yes", 1);
+
+ ConfNode *root = ConfGetNode("af-packet.0");
+ ConfNode *dflt = ConfGetNode("af-packet.1");
+ ConfGetChildValueBoolWithDefault(root, dflt, "use-mmap", &val);
+ if (val == 0) {
+ ConfDeInit();
+ ConfRestoreContextBackup();
+ return 0;
+ }
+
+ ConfSet("af-packet.0.use-mmap", "no", 1);
+ ConfGetChildValueBoolWithDefault(root, dflt, "use-mmap", &val);
+
+ ConfDeInit();
+ ConfRestoreContextBackup();
+ if (val) {
+ return 0;
+ }
+ return 1;
+}
+
/**
* Test the removal of a configuration node.
*/
UtRegisterTest("ConfNodeLookupChildTest", ConfNodeLookupChildTest, 1);
UtRegisterTest("ConfNodeLookupChildValueTest", ConfNodeLookupChildValueTest, 1);
UtRegisterTest("ConfNodeRemoveTest", ConfNodeRemoveTest, 1);
+ UtRegisterTest("ConfGetChildValueWithDefaultTest", ConfGetChildValueWithDefaultTest, 1);
+ UtRegisterTest("ConfGetChildValueIntWithDefaultTest", ConfGetChildValueIntWithDefaultTest, 1);
+ UtRegisterTest("ConfGetChildValueBoolWithDefaultTest", ConfGetChildValueBoolWithDefaultTest, 1);
}
#endif /* UNITTESTS */