Add dispatch test for rjp++
This commit is contained in:
parent
5bebbe1d33
commit
4bf41e8b42
@ -14,6 +14,9 @@ add_executable(parseplusplus "parse.cpp")
|
||||
set_target_properties(parseplusplus PROPERTIES OUTPUT_NAME parse)
|
||||
add_executable(outputplusplus "output.cpp")
|
||||
set_target_properties(outputplusplus PROPERTIES OUTPUT_NAME output)
|
||||
add_executable(dispatchplusplus "dispatch.cpp")
|
||||
set_target_properties(dispatchplusplus PROPERTIES OUTPUT_NAME dispatch)
|
||||
|
||||
add_test(NAME parse-test-plusplus COMMAND parseplusplus)
|
||||
add_test(NAME output-test-plusplus COMMAND outputplusplus)
|
||||
add_test(NAME dispatch-test-plusplus COMMAND dispatchplusplus)
|
||||
|
||||
48
rjp++/tests/dispatch.cpp
Normal file
48
rjp++/tests/dispatch.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "rjp_internal.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#define NUM_ELEMENTS 100
|
||||
|
||||
rjp::array initialize_array(int num){
|
||||
rjp::array root;
|
||||
|
||||
for(int i = 0;i < num;++i){
|
||||
switch(rand() % 4){
|
||||
case 0:
|
||||
root.add<rjp::integer>(rand() % 10);
|
||||
break;
|
||||
case 1:
|
||||
root.add<rjp::boolean>(rand() % 2);
|
||||
break;
|
||||
case 2:
|
||||
root.add<rjp::array>();
|
||||
break;
|
||||
case 3:
|
||||
root.add<rjp::object>();
|
||||
break;
|
||||
};
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
int main(){
|
||||
srand(time(0));
|
||||
|
||||
rjp::array root = initialize_array(NUM_ELEMENTS);
|
||||
|
||||
for(auto&& val : root){
|
||||
RJP_data_type d;
|
||||
rjp::dispatch(rjp::dispatcher{
|
||||
[&d](const rjp::value&){assert(false);},
|
||||
[&d](const rjp::integer&){d = rjp_json_integer;},
|
||||
[&d](const rjp::boolean&){d = rjp_json_boolean;},
|
||||
[&d](const rjp::array&){d = rjp_json_array;},
|
||||
[&d](const rjp::object&){d = rjp_json_object;},
|
||||
}, val);
|
||||
if(d != val.type()){
|
||||
printf("Dispatch error\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user