diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7d2669d..d054a14 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,3 +23,7 @@ target_link_libraries(Lists deepstate) add_executable(StreamingAndFormatting StreamingAndFormatting.cpp) target_link_libraries(StreamingAndFormatting deepstate) + +add_executable(Squares Squares.c) +target_link_libraries(Squares deepstate) +set_target_properties(Squares PROPERTIES COMPILE_DEFINITIONS "DEEPSTATE_TEST") diff --git a/examples/Squares.c b/examples/Squares.c new file mode 100644 index 0000000..1b4ac54 --- /dev/null +++ b/examples/Squares.c @@ -0,0 +1,42 @@ +#include +#include + +int square(int x) { + return x*x; +} + +#ifdef DEEPSTATE_TEST +#include +DeepState_EntryPoint(test_main) { + const char *new_args[2]; + new_args[0] = "deepstate"; + new_args[1] = DeepState_CStr(8); + + DeepState_Assert(0 == old_main(2, new_args)); +} + +int main(int argc, const char *argv[]) { + return 0 == DeepState_Run(); +} +// yes this is awful but avoids another ifdef +#define main old_main + +#endif + +int main(int argc, const char *argv[]) { + + if(argc != 2) { + printf("Usage: %s \n", argv[0]); + return -1; + } + int x = atoi(argv[1]); + int y = square(x); + + if(y + 4 == 29) { + printf("You found the secret number\n"); + return 0; + } else { + printf("Secret NOT found\n"); + return -1; + } +}