mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-13 10:32:58 +01:00
Fix custom_schema example and include it in the CMake build
This commit is contained in:
parent
630703c627
commit
048f4b5144
@ -26,6 +26,11 @@ include_directories(
|
||||
${Boost_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Custom schema validation example
|
||||
add_executable(custom_schema
|
||||
examples/custom_schema.cpp
|
||||
)
|
||||
|
||||
# External schema validation example
|
||||
add_executable(external_schema
|
||||
examples/external_schema.cpp
|
||||
@ -46,5 +51,6 @@ add_executable(test_suite
|
||||
set(TEST_LIBS gtest gtest_main jsoncpp)
|
||||
|
||||
target_link_libraries(test_suite ${TEST_LIBS} ${Boost_LIBRARIES})
|
||||
|
||||
target_link_libraries(custom_schema ${Boost_LIBRARIES})
|
||||
target_link_libraries(external_schema ${Boost_LIBRARIES})
|
||||
|
||||
|
@ -155,6 +155,13 @@ void addTypeConstraint(Schema &schema)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
cerr << "Usage:" << endl;
|
||||
cerr << " ./custom_schema <document>" << endl;
|
||||
cerr << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Load the document that is to be validated
|
||||
rapidjson::Document targetDocument;
|
||||
if (!valijson::utils::loadDocument(argv[1], targetDocument)) {
|
||||
@ -177,9 +184,13 @@ int main(int argc, char *argv[])
|
||||
ValidationResults::Error error;
|
||||
unsigned int errorNum = 1;
|
||||
while (results.popError(error)) {
|
||||
cerr << "Error #" << errorNum << std::endl
|
||||
<< " context: " << error.context << endl
|
||||
<< " desc: " << error.description << endl;
|
||||
cerr << "Error #" << errorNum << std::endl;
|
||||
cerr << " ";
|
||||
BOOST_FOREACH( const std::string contextElement, error.context ) {
|
||||
cerr << contextElement << " ";
|
||||
}
|
||||
cerr << endl;
|
||||
cerr << " - " << error.description << endl;
|
||||
++errorNum;
|
||||
}
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user