6 typedef unsigned char byte;
8 void taocrypt_test(void*);
9 void file_test(char*, byte*);
11 void client_test(void*);
12 void echoclient_test(void*);
14 THREAD_RETURN YASSL_API server_test(void*);
15 THREAD_RETURN YASSL_API echoserver_test(void*);
17 int main(int argc, char** argv)
19 func_args args(argc, argv);
20 func_args server_args(args);
22 // *** Crypto Test ***
24 assert(args.return_code == 0);
27 // *** Simple yaSSL client server test ***
30 start_thread(server_test, &server_args, &thread);
33 assert(args.return_code == 0);
35 assert(server_args.return_code == 0);
38 // *** Echo input yaSSL client server test ***
39 start_thread(echoserver_test, &server_args, &thread);
44 echo_args.argv = new char*[echo_args.argc];
45 for (int i = 0; i < echo_args.argc; i++)
46 echo_args.argv[i] = new char[32];
48 strcpy(echo_args.argv[0], "echoclient");
49 strcpy(echo_args.argv[1], "input");
50 strcpy(echo_args.argv[2], "output");
54 echoclient_test(&echo_args);
55 assert(echo_args.return_code == 0);
58 // *** Echo quit yaSSL client server test ***
60 strcpy(echo_args.argv[1], "quit");
62 echoclient_test(&echo_args);
63 assert(echo_args.return_code == 0);
65 assert(server_args.return_code == 0);
68 // input output compare
69 byte input[TaoCrypt::MD5::DIGEST_SIZE];
70 byte output[TaoCrypt::MD5::DIGEST_SIZE];
71 file_test("input", input);
72 file_test("output", output);
73 assert(memcmp(input, output, sizeof(input)) == 0);
75 printf("\nAll tests passed!\n");
78 for (int j = echo_args.argc; j >= 0; j--)
79 delete[] echo_args.argv[j];
80 delete[] echo_args.argv;
87 void start_thread(THREAD_FUNC fun, func_args* args, THREAD_TYPE* thread)
90 *thread = _beginthreadex(0, 0, fun, args, 0, 0);
92 pthread_create(thread, 0, fun, args);
97 void join_thread(THREAD_TYPE thread)
100 int res = WaitForSingleObject(reinterpret_cast<HANDLE>(thread), INFINITE);
101 assert(res == WAIT_OBJECT_0);
102 res = CloseHandle(reinterpret_cast<HANDLE>(thread));
105 pthread_join(thread, 0);