forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathov_util_test.cpp
More file actions
53 lines (45 loc) · 1.34 KB
/
ov_util_test.cpp
File metadata and controls
53 lines (45 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include <cstring>
#include "openvino/c/openvino.h"
#include "openvino/util/log.hpp"
namespace {
void test_log_msg(const char* msg) {
ov::util::LogHelper{ov::util::LOG_TYPE::_LOG_TYPE_INFO, "1664804", 101}.stream() << msg;
}
std::string got_message;
void callback_func(const char* msg) {
got_message = msg;
}
bool compare_msg(const char* msg) {
const auto msg_size = std::strlen(msg);
if (got_message.size() < msg_size) {
return false;
}
return std::strncmp(msg, got_message.data() + got_message.size() - msg_size, msg_size) == 0;
}
} // namespace
TEST(ov_util, set_log_callback) {
got_message.clear();
test_log_msg("default");
EXPECT_TRUE(got_message.empty());
ov_util_set_log_callback(&callback_func);
const char test_msg[] = "callback";
test_log_msg(test_msg);
EXPECT_TRUE(compare_msg(test_msg));
}
TEST(ov_util, reset_log_callback) {
got_message.clear();
ov_util_set_log_callback(&callback_func);
ov_util_reset_log_callback();
test_log_msg("default");
EXPECT_TRUE(got_message.empty());
}
TEST(ov_util, no_log_callback) {
got_message.clear();
ov_util_set_log_callback(NULL);
EXPECT_NO_THROW(test_log_msg("default"));
EXPECT_TRUE(got_message.empty());
}