Ana Gonzalez
Ana Gonzalez

Reputation: 33

How can I add test cases in CMake?

I have this code of a RC4 algorithm, how can I make a cmake document that include the 3 test cases of key and plain values?

void main(int argc, char *argv[]) {
    int i = 0;
    //unsigned char key[]={"Key"},plain[]={"Plaintext"};
    unsigned char key[]={"Wiki"},plain[]={"pedia"};
    //unsigned char key[]={"Secret"},plain[]={"Attack at dawn"};

    ksa(key,sizeof(key)-1);
    prga(sizeof(plain)-1);
    for (i=0;i<sizeof(plain)-1;i++){
        printf("%02X ",result[i]);
    }

    //Get cypher text
    for(i=0; i<sizeof(plain)-1;i++){
        cipher[i] = result[i] ^ plain[i];
    }
    printf("\n");
    for (i=0;i<sizeof(plain)-1;i++){
        printf("%02X ",cipher[i]);
    }
    printf("\n");
}

Upvotes: 1

Views: 129

Answers (1)

Florian
Florian

Reputation: 43058

Here is some CMake code that should give you a start (using plus ) when your rewrite your test program to accept the key and plain text values as command line parameters:

cmake_minimum_required(VERSION 2.8)
project(RC4Test C)

enable_testing()

add_executable(${PROJECT_NAME} main.c)

add_test(NAME Test1 COMMAND ${PROJECT_NAME} "Key" "Plaintext")
set_tests_properties(Test1 PROPERTIES PASS_REGULAR_EXPRESSION "...")

add_test(NAME Test2 COMMAND ${PROJECT_NAME} "Wiki" "pedia")
set_tests_properties(Test2 PROPERTIES PASS_REGULAR_EXPRESSION "...")

add_test(NAME Test3 COMMAND ${PROJECT_NAME} "Secret" "Attack at dawn")
set_tests_properties(Test3 PROPERTIES PASS_REGULAR_EXPRESSION "...")

Then you add whatever output is the correct one in PASS_REGULAR_EXPRESSION test property place holder "..." I put in the code.

And you are ready to go with:

> mkdir build
> cd build
> cmake ..
> cmake --build . --config Release
> ctest -V -C Release

References

Upvotes: 1

Related Questions