Anonymous avatar Anonymous committed 28fc3f1

Add testing of the query_partition_position function (fdisk@sv.gnu.org/fdisk--main--0--patch-36)
fdisk@sv.gnu.org/fdisk--main--0--patch-36
Keywords:

Comments (0)

Files changed (3)

tests/check_common.c

 }
 END_TEST
 
+int poss_compare(char* pos1, char* pos2) {
+	char all_poss[] = { 'b', 's', 'e', 'c', '\0' };
+	int i;
+	for (i = 0; all_poss[i]; i++) {
+		if ((strchr(pos1,all_poss[i]) == NULL) != 
+		    (strchr(pos2,all_poss[i]) == NULL))
+			return 0;
+	}
+	return 1;
+}
+
+/* TODO: Make this a function */
+#define run_pos_test(part,constraint,desired_opts,poss_ok,pos,strings) \
+	start = 2000LL; \
+	end = 21999LL; \
+	opts = UI_DEFAULT; \
+	pos_gets = 0; string_gets = 0; \
+	fail_unless(query_part_position("", NULL, &start, &end,  \
+	                                where.start, where.end, \
+	                                dev, (constraint), &opts), \
+	            "Query partition position %s failed", (part)); \
+	fail_unless(start == desired.start && end == desired.end, \
+	            "Partition position %s wrong. Was %llds-%llds, " \
+	            "should be %llds-%llds.", \
+	            (part), start, end, desired.start, desired.end); \
+	fail_unless(opts == (desired_opts), "Test %s opts wrong. " \
+	            "Was %d, should be %d.", opts, (desired_opts)); \
+	fail_unless(string_gets == (strings), "%s prompted wrong times." \
+	            "Strings %d, should be %d. Pos %d should be %d.", \
+	             (part), string_gets, (strings), pos_gets, (pos)); \
+	fail_unless(poss_compare(pos_poss,(poss_ok)), \
+	            "%s: incorrect possibilities. Got %s, should be %s.", \
+	             (part), pos_poss, (poss_ok))
+
 START_TEST (test_partpos) {
-	PedGeometry geom;
+	PedGeometry desired;
 	PedGeometry where;
 	PedSector start,end;
+
+	PedConstraint *constraint = ped_device_get_constraint(dev);
+
+	UIOpts opts = UI_DEFAULT;
+
+	uiquery.getpartpos = getpartpos;
+	uiquery.getstring = getstring;
+
+	string[0][BUFSIZE] = 0;
+	/* A:    We test without constraint */
+
+	/*   A1: We test with where = partition*/
 	ped_geometry_init(&where,dev,2000LL,20000LL);
-	ped_geometry_init(&geom,dev,2000LL,20000LL);
-	fail_unless(perform_mklabel(dev,&disk,ped_disk_type_get("msdos")),
-	            "We could create the label for partpos test");
-	/* fail_unless(_mkpart(0, where.start, where.end, PED_PARTITION_NORMAL,
-	 *                   fs_type, NULL, perform_mkpart),
-	 *           "Failed to create partpos test partition")
-	 */
-	uiquery.getpartpos = getpartpos;
-	/* A: We test without constraint */
+	/* Start */
+	ped_geometry_init(&desired,dev,2000LL,4000LL);
+	partpos = 's';
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	run_pos_test("A1s",NULL,UI_DEFAULT,"sec",1,1);
+	/* End */
+	ped_geometry_init(&desired,dev,where.end-4000LL+1LL,4000LL);
+	partpos = 'e';
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	run_pos_test("A1e",NULL,UI_DEFAULT,"sec",1,1);
+	/* Custom */
+	ped_geometry_init(&desired,dev,where.start,where.length);
+	partpos = 'c';
+	run_pos_test("A1c",NULL,UI_CUSTOM_VALUES,"sec",1,0);
+	
+	/*   A2: We test with where = big */
+	ped_geometry_init(&where,dev,0LL,24000LL);
+	/* Start */
+	ped_geometry_init(&desired,dev,2000LL,4000LL);
+	partpos = 's';
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	run_pos_test("A2s",NULL,UI_DEFAULT,"bsec",1,1);
+	/* Beginning */
+	ped_geometry_init(&desired,dev,where.start,4000LL);
+	partpos = 'b';
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	run_pos_test("A1s",NULL,UI_DEFAULT,"bsec",1,1);
+	/* End */
+	ped_geometry_init(&desired,dev,where.end-4000LL+1LL,4000LL);
+	partpos = 'e';
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	run_pos_test("A2e",NULL,UI_DEFAULT,"bsec",1,1);
+	/* Custom */
+	ped_geometry_init(&desired,dev,2000LL,20000LL);
+	partpos = 'c';
+	run_pos_test("A2c",NULL,UI_CUSTOM_VALUES,"bsec",1,0);
 
 	/* B: We test with some constraint */
+	/*   B1: We test with where = partition, Start*/
+	ped_geometry_init(&where,dev,2000LL,20000LL);
+	ped_geometry_init(&desired,dev,2000LL,4000LL);
+	partpos = 's';
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	run_pos_test("B1s",constraint,UI_DEFAULT,"sec",1,1);
+	/*   B2: We test with where = big, End */
+	ped_geometry_init(&where,dev,0LL,24000LL);
+	ped_geometry_init(&desired,dev,where.end-4000LL+1LL,4000LL);
+	partpos = 'e';
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	run_pos_test("B2e",constraint,UI_DEFAULT,"bsec",1,1);
+	
 	/* C: We test with constraint of a partition with unmovable start */
+	constraint->start_align->grain_size = 0;
+	/*   C1s: We test with where = partition*/
+	ped_geometry_init(&where,dev,2000LL,20000LL);
+	ped_geometry_init(&desired,dev,2000LL,4000LL);
+	partpos = 'j'; /* We don't need to serve this right, right? */
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	strncpy(pos_poss,"bsc",sizeof(pos_poss));
+	run_pos_test("C1s",constraint,UI_DEFAULT,"bsc",0,1);
+	/* C2s: We test with where = big */
+	ped_geometry_init(&where,dev,0LL,24000LL);
+	ped_geometry_init(&desired,dev,2000LL,4000LL);
+	partpos = 'j'; /* We don't need to serve this right, right? */
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	strncpy(pos_poss,"sc",sizeof(pos_poss));
+	run_pos_test("C2s",constraint,UI_DEFAULT,"sc",0,1);
 
-	
+	/* D: Another constraint */
+	ped_constraint_destroy(constraint);
+	constraint = ped_device_get_constraint(dev);
+	ped_geometry_set(constraint->start_range,2000LL,1LL);
+	ped_geometry_init(&where,dev,2000LL,20000LL);
+	ped_geometry_init(&desired,dev,2000LL,4000LL);
+	partpos = 'j'; /* We don't need to serve this right, right? */
+	snprintf(string[0],BUFSIZE,"%llds",desired.length);
+	strncpy(pos_poss,"bsc",sizeof(pos_poss));
+	run_pos_test("D1s",constraint,UI_DEFAULT,"bsc",0,1);
+
+
 }
 END_TEST
 
 	tcase_add_test(tc_label, test_mklabel);
 	tcase_add_test(tc_juggle, test_jugglepart);
 	tcase_set_timeout(tc_chsize, 10);
+	tcase_add_test(tc_chsize, test_partpos);
 	tcase_add_test(tc_chsize, test_chsize_msdos);
 	tcase_add_test(tc_chsize, test_chsize_bsd);
 	tcase_add_test(tc_chsize, test_chsize_pc98);

tests/functions.c

 	return 1;
 }
 
-int part_pos;
+int partpos;
 int pos_gets;
+char pos_poss[10];
 int getpartpos (const char* prompt, const void* context,
                        const char *possibilities)
 {
 	/* We count how much times this was called */
 	pos_gets++;
-	return part_pos;
+	/* And save the possibilities */
+	strncpy(pos_poss, possibilities, sizeof(pos_poss));
+
+	return partpos;
 }
 
 
 	
 	/* NOTE: This might blow up if ltype is less than three chars */
 	/* FIXME: This checks works differently on LE and BE platforms */
-	srand(1 + opts + ((int) ltype));
+	srand(2 + opts + ((int) ltype));
 	/* We will resize create 4 partitions */
 	if (is_mac) {
 		part = ped_disk_get_partition(disk,1);

tests/functions.h

 extern PedFileSystemType *fs_type;
 extern int getfstype (const char* prompt, PedFileSystemType **value);
 
-extern int part_pos;
+extern int partpos;
 extern int pos_gets;
+extern char pos_poss[10];
 extern int getpartpos (const char* prompt, const void* context,
                        const char *possibilities);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.