public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2/test/unit config_t.c
@ 2011-12-11 15:45 mornfall
  0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2011-12-11 15:45 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2011-12-11 15:45:15

Modified files:
	test/unit      : config_t.c 

Log message:
	Add a unit test for dm_config_clone_node.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/unit/config_t.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2

--- LVM2/test/unit/config_t.c	2011/12/11 15:19:41	1.1
+++ LVM2/test/unit/config_t.c	2011/12/11 15:45:14	1.2
@@ -27,25 +27,26 @@
 	return 0;
 }
 
+static const char *conf =
+	"id = \"yada-yada\"\n"
+	"seqno = 15\n"
+	"status = [\"READ\", \"WRITE\"]\n"
+	"flags = []\n"
+	"extent_size = 8192\n"
+	"physical_volumes {\n"
+	"    pv0 {\n"
+	"        id = \"abcd-efgh\"\n"
+	"    }\n"
+	"    pv1 {\n"
+	"        id = \"bbcd-efgh\"\n"
+	"    }\n"
+	"    pv2 {\n"
+	"        id = \"cbcd-efgh\"\n"
+	"    }\n"
+	"}\n";
+
 static void test_parse()
 {
-	const char *conf =
-		"id = \"yada-yada\"\n"
-		"seqno = 15\n"
-		"status = [\"READ\", \"WRITE\"]\n"
-		"flags = []\n"
-		"extent_size = 8192\n"
-		"physical_volumes {\n"
-		"    pv0 {\n"
-		"        id = \"abcd-efgh\"\n"
-		"    }\n"
-		"    pv1 {\n"
-		"        id = \"bbcd-efgh\"\n"
-		"    }\n"
-		"    pv2 {\n"
-		"        id = \"cbcd-efgh\"\n"
-		"    }\n"
-		"}\n";
 	struct dm_config_tree *tree = dm_config_from_string(conf);
 	struct dm_config_value *value;
 
@@ -69,15 +70,53 @@
 	// CU_ASSERT(!dm_config_get_list(tree->root, "extent_size", NULL));
 
 	CU_ASSERT(dm_config_get_list(tree->root, "flags", &value));
-	CU_ASSERT(value->next == NULL);
+	CU_ASSERT(value->next == NULL); /* an empty list */
 	CU_ASSERT(dm_config_get_list(tree->root, "status", &value));
-	CU_ASSERT(value->next != NULL);
+	CU_ASSERT(value->next != NULL); /* a non-empty list */
 
 	dm_config_destroy(tree);
 }
 
+static void test_clone()
+{
+	struct dm_config_tree *tree = dm_config_from_string(conf);
+	struct dm_config_node *n = dm_config_clone_node(tree, tree->root, 1);
+	struct dm_config_value *value;
+
+	/* Check that the nodes are actually distinct. */
+	CU_ASSERT(n != tree->root);
+	CU_ASSERT(n->sib != tree->root->sib);
+	CU_ASSERT(dm_config_find_node(n, "physical_volumes") != NULL);
+	CU_ASSERT(dm_config_find_node(tree->root, "physical_volumes") != NULL);
+	CU_ASSERT(dm_config_find_node(n, "physical_volumes") != dm_config_find_node(tree->root, "physical_volumes"));
+
+	CU_ASSERT(dm_config_has_node(n, "id"));
+	CU_ASSERT(dm_config_has_node(n, "physical_volumes"));
+	CU_ASSERT(dm_config_has_node(n, "physical_volumes/pv0"));
+	CU_ASSERT(dm_config_has_node(n, "physical_volumes/pv0/id"));
+
+	CU_ASSERT(!strcmp(dm_config_find_str(n, "id", "foo"), "yada-yada"));
+	CU_ASSERT(!strcmp(dm_config_find_str(n, "idt", "foo"), "foo"));
+
+	CU_ASSERT(!strcmp(dm_config_find_str(n, "physical_volumes/pv0/bb", "foo"), "foo"));
+	CU_ASSERT(!strcmp(dm_config_find_str(n, "physical_volumes/pv0/id", "foo"), "abcd-efgh"));
+
+	CU_ASSERT(!dm_config_get_uint32(n, "id", NULL));
+	CU_ASSERT(dm_config_get_uint32(n, "extent_size", NULL));
+
+	/* FIXME: Currently everything parses as a list, even if it's not */
+	// CU_ASSERT(!dm_config_get_list(tree->root, "id", NULL));
+	// CU_ASSERT(!dm_config_get_list(tree->root, "extent_size", NULL));
+
+	CU_ASSERT(dm_config_get_list(n, "flags", &value));
+	CU_ASSERT(value->next == NULL); /* an empty list */
+	CU_ASSERT(dm_config_get_list(n, "status", &value));
+	CU_ASSERT(value->next != NULL); /* a non-empty list */
+}
+
 CU_TestInfo config_list[] = {
 	{ (char*)"parse", test_parse },
+	{ (char*)"clone", test_clone },
 	CU_TEST_INFO_NULL
 };
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* LVM2/test/unit config_t.c
@ 2012-01-09 12:29 zkabelac
  0 siblings, 0 replies; 3+ messages in thread
From: zkabelac @ 2012-01-09 12:29 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2012-01-09 12:29:15

Modified files:
	test/unit      : config_t.c 

Log message:
	Minor oldstyle warning update

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/unit/config_t.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5

--- LVM2/test/unit/config_t.c	2011/12/18 23:56:36	1.4
+++ LVM2/test/unit/config_t.c	2012/01/09 12:29:15	1.5
@@ -131,7 +131,7 @@
 	dm_config_destroy(tree);
 }
 
-static void test_cascade()
+static void test_cascade(void)
 {
 	struct dm_config_tree *t1 = dm_config_from_string(conf),
 		              *t2 = dm_config_from_string(overlay),


^ permalink raw reply	[flat|nested] 3+ messages in thread

* LVM2/test/unit config_t.c
@ 2011-12-18 23:56 mornfall
  0 siblings, 0 replies; 3+ messages in thread
From: mornfall @ 2011-12-18 23:56 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	mornfall@sourceware.org	2011-12-18 23:56:36

Modified files:
	test/unit      : config_t.c 

Log message:
	Add a unit test for config cascade (overlay). Needs expanding though.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/unit/config_t.c.diff?cvsroot=lvm2&r1=1.3&r2=1.4

--- LVM2/test/unit/config_t.c	2011/12/13 12:08:42	1.3
+++ LVM2/test/unit/config_t.c	2011/12/18 23:56:36	1.4
@@ -48,6 +48,18 @@
 	"    }\n"
 	"}\n";
 
+static const char *overlay =
+	"id = \"yoda-soda\"\n"
+	"flags = [\"FOO\"]\n"
+	"physical_volumes {\n"
+	"    pv1 {\n"
+	"        id = \"hgfe-dcba\"\n"
+	"    }\n"
+	"    pv3 {\n"
+	"        id = \"dbcd-efgh\"\n"
+	"    }\n"
+	"}\n";
+
 static void test_parse(void)
 {
 	struct dm_config_tree *tree = dm_config_from_string(conf);
@@ -119,8 +131,26 @@
 	dm_config_destroy(tree);
 }
 
+static void test_cascade()
+{
+	struct dm_config_tree *t1 = dm_config_from_string(conf),
+		              *t2 = dm_config_from_string(overlay),
+		              *tree = dm_config_insert_cascaded_tree(t2, t1);
+
+	CU_ASSERT(!strcmp(dm_config_tree_find_str(tree, "id", "foo"), "yoda-soda"));
+	CU_ASSERT(!strcmp(dm_config_tree_find_str(tree, "idt", "foo"), "foo"));
+
+	CU_ASSERT(!strcmp(dm_config_tree_find_str(tree, "physical_volumes/pv0/bb", "foo"), "foo"));
+	CU_ASSERT(!strcmp(dm_config_tree_find_str(tree, "physical_volumes/pv1/id", "foo"), "hgfe-dcba"));
+	CU_ASSERT(!strcmp(dm_config_tree_find_str(tree, "physical_volumes/pv3/id", "foo"), "dbcd-efgh"));
+
+	dm_config_destroy(t1);
+	dm_config_destroy(t2);
+}
+
 CU_TestInfo config_list[] = {
 	{ (char*)"parse", test_parse },
 	{ (char*)"clone", test_clone },
+	{ (char*)"cascade", test_cascade },
 	CU_TEST_INFO_NULL
 };


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-09 12:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-11 15:45 LVM2/test/unit config_t.c mornfall
2011-12-18 23:56 mornfall
2012-01-09 12:29 zkabelac

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).