Skip to content

Commit

Permalink
improving unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kakwa committed May 2, 2018
1 parent c5f5f6e commit 739f0e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ficlip.c
Expand Up @@ -835,7 +835,7 @@ int fi_validate_path(FI_PATH *path) {
break;
case FI_SEG_MOVE:
if (in_path)
return false;
return ERR_PATH_NO_MZ;
in_path = true;
break;
case FI_SEG_LINE:
Expand Down
25 changes: 25 additions & 0 deletions tests/ficlip-test.c
Expand Up @@ -96,6 +96,8 @@ void test_parse() {
void test_validate() {
FI_PATH *path;
int err;

// MISSING "M" at the begining
int ret = _parse_path(
"L 10.0,23.5432 L 0.5,42.987 A 30 50 45.1 1 1 162.55 140.45 "
"C 50.2,0.567 40,10 5,5.69 Q 123,1.3 22.3,123 Z",
Expand All @@ -106,6 +108,7 @@ void test_validate() {
CU_ASSERT(err == ERR_PATH_NO_MZ);
fi_free_path(path);

// MISSING "Z" at the end
ret = _parse_path(
"M 0.0,1.1 L 10.0,23.5432 L 0.5,42.987 A 30 50 45.1 1 1 162.55 140.45 "
"C 50.2,0.567 40,10 5,5.69 Q 123,1.3 22.3,123 ",
Expand All @@ -116,13 +119,35 @@ void test_validate() {
CU_ASSERT(err == ERR_PATH_NO_MZ);
fi_free_path(path);

// SECTION OF THE PATH TOO SHORT (NEED AT LEAST 1 M AND 2 L FOR A POLYGON)
ret = _parse_path("M 0.0,1.1 L 10.0,23.5432 Z", &path);

CU_ASSERT(ret == 0);
err = fi_validate_path(path);
CU_ASSERT(err == ERR_PATH_SECTION_TOO_SHORT);
fi_free_path(path);

// DOUBLE Z
ret = _parse_path("M 0.0,1.1 L 10.0,23.5432 L 123,1.3 Z Z M 0.0,1.1 L "
"10.0,23.5432 L 123,1.3 Z",
&path);

CU_ASSERT(ret == 0);
err = fi_validate_path(path);
CU_ASSERT(err == ERR_PATH_NO_MZ);
fi_free_path(path);

// 2 M IN A SECTION
ret = _parse_path("M 0.0,1.1 L 10.0,23.5432 L 123,1.3 M 0.0,1.1 L "
"10.0,23.5432 L 123,1.3 Z",
&path);

CU_ASSERT(ret == 0);
err = fi_validate_path(path);
CU_ASSERT(err == ERR_PATH_NO_MZ);
fi_free_path(path);

// VALID PATH WITH 2 SECTIONS
ret = _parse_path("M 0.0,1.1 L 10.0,23.5432 L 123,1.3 Z M 0.0,1.1 L "
"10.0,23.5432 L 123,1.3 Z",
&path);
Expand Down

0 comments on commit 739f0e4

Please sign in to comment.