我有这个RC4算法的代码,如何制作包含3个关键和普通值测试用例的cmake文档?
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");
}
答案 0 :(得分:1)
当你重写测试程序以接受键和纯文本值作为命令行参数时,这里有一些CMake代码可以给你一个开始(使用cmake加ctest):
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 "...")
然后在PASS_REGULAR_EXPRESSION
测试属性占位符"..."
中添加正确的输出,我输入代码。
你准备好了:
> mkdir build
> cd build
> cmake ..
> cmake --build . --config Release
> ctest -V -C Release
<强>参考强>