void test_target_level (void) { cut_set_log_level(CUT_LOG_LEVEL_DEFAULT); logger = cut_logger_new(); g_signal_connect(logger, "log", G_CALLBACK(cut_logger_default_log_handler), NULL); original_print_hander = g_set_print_handler(print_handler); cut_logger_log(logger, "domain", CUT_LOG_LEVEL_INFO, "file", 29, "function", "message"); g_set_print_handler(original_print_hander); original_print_hander = NULL; cut_assert_equal_string("", stdout_string->str); cut_logger_set_target_level(logger, CUT_LOG_LEVEL_INFO); original_print_hander = g_set_print_handler(print_handler); cut_logger_log(logger, "domain", CUT_LOG_LEVEL_INFO, "file", 29, "function", "message"); g_set_print_handler(original_print_hander); original_print_hander = NULL; cut_assert_match("message", stdout_string->str); }
void test_args_salt_binary() { char *salt = NULL, *hash = NULL; int fd, n; size_t len, bytes = 0; len = BCRYPT_BLOWFISH_SALT_REQUIRED_LEN; salt = malloc(len + 1); memset(salt, 0, len + 1); fd = open("/dev/urandom", O_RDONLY); if (fd >= 0) { while (bytes < len) { n = read(fd, salt + bytes, len - bytes); if (n < 0) { break; } bytes += (size_t)n; } close(fd); } hash = password_hash("password", NULL, salt, BCRYPT_BLOWFISH_COST); cut_assert_not_null(hash); cut_assert_equal_int(60, strlen(hash)); cut_assert_match("\\$2y\\$10\\$.*", hash); free(salt); free(hash); }
/** * print_timer() 関数テスト * * @return なし */ void test_print_timer(void) { unsigned int t = 0, time = 0; /* タイマ用変数 */ int fd = -1; /* ファイルディスクリプタ */ int retval = 0; /* 戻り値 */ char actual[BUF_SIZE] = {0}; /* 実際の文字列 */ const char expected[] = /* 期待する文字列 */ "time of time: [0-9]+\\.[0-9]+\\[msec\\]"; start_timer(&t); time = stop_timer(&t); fd = pipe_fd(STDERR_FILENO); if (fd < 0) { cut_error("pipe_fd=%d(%d)", fd, errno); return; } print_timer(time); retval = read(fd, actual, sizeof(actual)); if (retval < 0) { cut_fail("read=%d(%d)", fd, errno); goto error_handler; } dbglog("actual=%s", actual); cut_assert_match(expected, actual, cut_message("expected=%s actual=%s", expected, actual)); error_handler: close_fd(&fd, NULL); }
void test_args_algo() { char *hash = password_hash("password", "algorithm", NULL, BCRYPT_BLOWFISH_COST); cut_assert_not_null(hash); cut_assert_equal_int(60, strlen(hash)); cut_assert_match("\\$2y\\$10\\$.*", hash); free(hash); }
void test_console_output (void) { original_print_hander = g_set_print_handler(print_handler); cut_set_log_level(CUT_LOG_LEVEL_INFO); cut_log_info("info"); cut_log_info("end-of-log"); g_set_print_handler(original_print_hander); original_print_hander = NULL; cut_assert_match("info", stdout_string->str); }