Skip to content

Commit

Permalink
V1.1 (#3)
Browse files Browse the repository at this point in the history
Switched to [µnit](https://nemequ.github.io/munit/) for unit tests.
  • Loading branch information
BlockoS authored Mar 16, 2018
1 parent 3ac96fe commit a43236b
Show file tree
Hide file tree
Showing 41 changed files with 5,071 additions and 1,799 deletions.
61 changes: 21 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,35 @@ add_custom_target(doc
COMMENT "Generating API documentation with Doxygen"
VERBATIM )

set(TINY_PDS_TEST_SOURCE_FILES test/utils.c test/test.c)

enable_testing()

add_library(munit STATIC ${CMAKE_CURRENT_SOURCE_DIR}/test/munit/munit.c)
target_include_directories(munit PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test/munit>)
set_property(TARGET munit PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test/munit>)

include_directories(.)
add_executable(PDS_find_first test/PDS_find_first.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_datetime test/PDS_parse_datetime.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_identifier test/PDS_parse_identifier.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_int_base test/PDS_parse_int_base.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_int test/PDS_parse_int.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_real test/PDS_parse_real.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_sequence test/PDS_parse_sequence.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_set test/PDS_parse_set.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_statement test/PDS_parse_statement.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_string test/PDS_parse_string.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_symbol test/PDS_parse_symbol.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse_unit test/PDS_parse_unit.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_skip_whitespaces test/PDS_skip_whitespaces.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_string_case_compare test/PDS_string_case_compare.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_string_compare test/PDS_string_compare.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_trim test/PDS_trim.c ${TINY_PDS_TEST_SOURCE_FILES})
add_executable(PDS_parse test/PDS_parse.c ${TINY_PDS_TEST_SOURCE_FILES})

add_executable(PDS_DOM_parse test/PDS_DOM_parse.c ${TINY_PDS_TEST_SOURCE_FILES})

add_executable(PDS_string_tests test/PDS_string_tests.c)
target_link_libraries(PDS_string_tests munit)

add_executable(PDS_parse_tests test/PDS_parse_tests.c)
target_link_libraries(PDS_parse_tests munit)

add_executable(PDS_parse test/PDS_parse.c test/utils.c)

add_executable(PDS_DOM_parse test/PDS_DOM_parse.c test/utils.c)
target_link_libraries(PDS_DOM_parse tinypds)

add_executable(PDS_DOM_find test/PDS_DOM_find.c ${TINY_PDS_TEST_SOURCE_FILES})
target_link_libraries(PDS_DOM_find tinypds tinypds_dom)

add_test(PDS_find_first PDS_find_first )
add_test(PDS_parse_datetime PDS_parse_datetime)
add_test(PDS_parse_identifier PDS_parse_identifier)
add_test(PDS_parse_int_base PDS_parse_int_base)
add_test(PDS_parse_int PDS_parse_int)
add_test(PDS_parse_real PDS_parse_real)
add_test(PDS_parse_sequence PDS_parse_sequence)
add_test(PDS_parse_set PDS_parse_set)
add_test(PDS_parse_statement PDS_parse_statement)
add_test(PDS_parse_string PDS_parse_string)
add_test(PDS_parse_symbol PDS_parse_symbol)
add_test(PDS_parse_unit PDS_parse_unit)
add_test(PDS_skip_whitespaces PDS_skip_whitespaces)
add_test(PDS_string_case_compare PDS_string_case_compare)
add_test(PDS_string_compare PDS_string_compare)
add_test(PDS_trim PDS_trim)
add_executable(PDS_DOM_find test/PDS_DOM_find.c)
target_link_libraries(PDS_DOM_find tinypds_dom tinypds munit)

add_test(PDS_string_tests PDS_string_tests)
add_test(PDS_parse_tests PDS_parse_tests)
add_test(PDS_parse_GASPRA_SUMM_RTN.LBL PDS_parse ${CMAKE_CURRENT_SOURCE_DIR}/test/data/GASPRA_SUMM_RTN.LBL)
add_test(PDS_parse_LOR_0034851929_0X630_ENG_1.LBL PDS_parse ${CMAKE_CURRENT_SOURCE_DIR}/test/data/LOR_0034851929_0X630_ENG_1.LBL)
add_test(PDS_parse_W20140403T020157750ID20F12.IMG PDS_parse ${CMAKE_CURRENT_SOURCE_DIR}/test/data/W20140403T020157750ID20F12.IMG)
add_test(PDS_parse_AMI_LR3_R00976_00031_00040.IMG PDS_parse ${CMAKE_CURRENT_SOURCE_DIR}/test/data/AMI_LR3_R00976_00031_00040.IMG)

add_test(PDS_DOM_parse_W20140403T020157750ID20F12.IMG PDS_DOM_parse ${CMAKE_CURRENT_SOURCE_DIR}/test/data/W20140403T020157750ID20F12.IMG)
add_test(PDS_DOM_parse_0844636876_lvl1_0.lbl PDS_DOM_parse ${CMAKE_CURRENT_SOURCE_DIR}/test/data/0844636876_lvl1_0.lbl)
add_test(PDS_DOM_parse_hayabusa_20050907_20050908_v01.lbl PDS_DOM_parse ${CMAKE_CURRENT_SOURCE_DIR}/test/data/hayabusa_20050907_20050908_v01.lbl)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,4 @@ Finally the parsing is started by calling **PDS_parse**. An implementation examp
## License ##
The MIT License
Copyright (c) 2016 Vincent Cruz
Copyright (c) 2018 Vincent Cruz
1 change: 1 addition & 0 deletions examples/rosetta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(CFITSIO)

include_directories(${CFITSIO_INCLUDE_DIR} ../..)
include_directories(${CFITSIO_INCLUDE_DIR} ../../dom)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wshadow -Wextra")

Expand Down
218 changes: 116 additions & 102 deletions test/PDS_DOM_find.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <munit.h>

#include <tinypds.h>
#include <tinypds_dom.h>

#include "test.h"

static const char *pds_string =
"PDS_VERSION_ID = PDS3\r\n"
"OBJECT = object_0\r\n"
Expand Down Expand Up @@ -45,104 +41,122 @@ static const char *pds_string =
"ATTRIBUTE_8 = 14\r\n"
"END\r\n";

PDS_item *item = NULL;
static void* pds_dom_setup(const MunitParameter params[], void* user_data) {
(void)params;
(void)user_data;
return malloc(sizeof(PDS_item**));
}

void cleanup()
{
if(item)
{
PDS_DOM_delete(item);
}
static void pds_dom_tear_down(void* fixture) {
if(NULL == fixture) {
return;
}
PDS_item **item = (PDS_item**)fixture;
if(*item) {
PDS_DOM_delete(*item);
}
free(item);
}

int main()
{
PDS_item *found;
PDS_scalar scalar;
PDS_error_description err;
int ret;

atexit(cleanup);

ret = PDS_DOM_parse(pds_string, strlen(pds_string), &item, &err);
if(!ret)
{
fprintf(stderr, "parse error line %d:%d: %s\n", err.number, err.position, err.msg);
return EXIT_FAILURE;
}

found = PDS_DOM_find("ATTRIBUTE_0", item, PDS_ONLY_SIBLINGS, 0);
check(NULL != found);
check(PDS_DOM_is_attribute(found));
check(PDS_SINGLE == PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
check(ret);
check(PDS_INTEGER_VALUE == scalar.type);
check(13 == scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_8", found, PDS_ONLY_SIBLINGS, 0);
check(NULL != found);
check(PDS_DOM_is_attribute(found));
check(PDS_SINGLE == PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
check(ret);
check(PDS_INTEGER_VALUE == scalar.type);
check(14 == scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_1", item, PDS_ONLY_SIBLINGS, 1);
check(NULL == found);

found = PDS_DOM_find("PDS_VERSION_ID", item, PDS_ONLY_SIBLINGS, 1);
check(NULL != found);

found = PDS_DOM_find("ATTRIBUTE_8", item, PDS_ONLY_CHILDREN, 0);
check(NULL == found);

found = PDS_DOM_find("object_0", item, PDS_ONLY_SIBLINGS, 0);
check(NULL != found);
check(PDS_DOM_is_object(found));

check(NULL == PDS_DOM_find("ATTRIBUTE_8", found, PDS_ONLY_CHILDREN, 0));

found = PDS_DOM_find("object_1", found, PDS_ONLY_CHILDREN, 0);
check(NULL != found);
check(PDS_DOM_is_object(found));

found = PDS_DOM_find("ATTRIBUTE_8", found, PDS_CHILDREN_RECURSIVE, 0);
check(NULL != found);
check(PDS_DOM_is_attribute(found));
check(PDS_SINGLE == PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
check(ret);
check(PDS_INTEGER_VALUE == scalar.type);
check(8 == scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_E", item, PDS_SIBLINGS_RECURSIVE, 1);
check(NULL != found);
check(PDS_DOM_is_attribute(found));
check(PDS_SINGLE == PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
check(ret);
check(PDS_INTEGER_VALUE == scalar.type);
check(16 == scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_2", item, PDS_SIBLINGS_RECURSIVE, 0);
check(NULL != found);
check(PDS_DOM_is_attribute(found));
check(PDS_SINGLE == PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
check(ret);
check(PDS_INTEGER_VALUE == scalar.type);
check(2 == scalar.integer.value);

found = PDS_DOM_find("object_3", found, PDS_SIBLINGS_RECURSIVE, 0);
check(NULL != found);
check(PDS_DOM_is_object(found));

return EXIT_SUCCESS;
MunitResult pds_dom_find_test(const MunitParameter params[], void* fixture) {
(void)params;
PDS_item **item = (PDS_item**)fixture;
PDS_item *found;
PDS_scalar scalar;
PDS_error_description err;
int ret;

ret = PDS_DOM_parse(pds_string, strlen(pds_string), item, &err);
if(!ret) {
munit_errorf("parse error line %d:%d: %s\n", err.number, err.position, err.msg);
return MUNIT_FAIL;
}

found = PDS_DOM_find("ATTRIBUTE_0", *item, PDS_ONLY_SIBLINGS, 0);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_attribute(found));
munit_assert_int(PDS_SINGLE, ==, PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
munit_assert_true(ret);
munit_assert_int(PDS_INTEGER_VALUE, ==, scalar.type);
munit_assert_int(13, ==, scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_8", found, PDS_ONLY_SIBLINGS, 0);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_attribute(found));
munit_assert_int(PDS_SINGLE, ==, PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
munit_assert_true(ret);
munit_assert_int(PDS_INTEGER_VALUE, ==, scalar.type);
munit_assert_int(14, ==, scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_1", *item, PDS_ONLY_SIBLINGS, 1);
munit_assert_ptr_equal(NULL, found);

found = PDS_DOM_find("PDS_VERSION_ID", *item, PDS_ONLY_SIBLINGS, 1);
munit_assert_ptr_not_equal(NULL, found);

found = PDS_DOM_find("ATTRIBUTE_8", *item, PDS_ONLY_CHILDREN, 0);
munit_assert_ptr_equal(NULL, found);

found = PDS_DOM_find("object_0", *item, PDS_ONLY_SIBLINGS, 0);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_object(found));

munit_assert_ptr_equal(NULL, PDS_DOM_find("ATTRIBUTE_8", found, PDS_ONLY_CHILDREN, 0));

found = PDS_DOM_find("object_1", found, PDS_ONLY_CHILDREN, 0);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_object(found));

found = PDS_DOM_find("ATTRIBUTE_8", found, PDS_CHILDREN_RECURSIVE, 0);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_attribute(found));
munit_assert_int(PDS_SINGLE, ==, PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
munit_assert_true(ret);
munit_assert_int(PDS_INTEGER_VALUE, ==, scalar.type);
munit_assert_int(8, ==, scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_E", *item, PDS_SIBLINGS_RECURSIVE, 1);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_attribute(found));
munit_assert_int(PDS_SINGLE, ==, PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
munit_assert_true(ret);
munit_assert_int(PDS_INTEGER_VALUE, ==, scalar.type);
munit_assert_int(16, ==, scalar.integer.value);

found = PDS_DOM_find("ATTRIBUTE_2", *item, PDS_SIBLINGS_RECURSIVE, 0);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_attribute(found));
munit_assert_int(PDS_SINGLE, ==, PDS_DOM_scalar_typeof(found));

ret = PDS_DOM_scalar_get(found, &scalar);
munit_assert_true(ret);
munit_assert_int(PDS_INTEGER_VALUE, ==, scalar.type);
munit_assert_int(2, ==, scalar.integer.value);

found = PDS_DOM_find("object_3", found, PDS_SIBLINGS_RECURSIVE, 0);
munit_assert_ptr_not_equal(NULL, found);
munit_assert_true(PDS_DOM_is_object(found));

return MUNIT_OK;
}

static MunitTest pds_dom_tests[] = {
{ "find", pds_dom_find_test, pds_dom_setup, pds_dom_tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};

static const MunitSuite pds_dom_suite = {
"PDS DOM test suite", pds_dom_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
};

int main (int argc, char* const* argv) {
return munit_suite_main(&pds_dom_suite, NULL, argc, argv);
}
Loading

0 comments on commit a43236b

Please sign in to comment.