Skip to content

Commit db1779e

Browse files
committed
[utest][cpp]add cpp-smartptr testcase.
1 parent 618516e commit db1779e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-09-19 Rbb666 the first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include "utest.h"
13+
#include <memory>
14+
15+
/**
16+
* @brief Test unique_ptr basic operations.
17+
*/
18+
static void test_unique_ptr(void)
19+
{
20+
std::unique_ptr<int> p(new int(42));
21+
uassert_int_equal(*p, 42);
22+
*p = 24;
23+
uassert_int_equal(*p, 24);
24+
}
25+
26+
/**
27+
* @brief Test shared_ptr basic operations.
28+
*/
29+
static void test_shared_ptr(void)
30+
{
31+
std::shared_ptr<int> p1(new int(42));
32+
std::shared_ptr<int> p2 = p1;
33+
uassert_int_equal(*p1, 42);
34+
uassert_int_equal(*p2, 42);
35+
uassert_int_equal(p1.use_count(), 2);
36+
}
37+
38+
static rt_err_t utest_tc_init(void)
39+
{
40+
return RT_EOK;
41+
}
42+
43+
static rt_err_t utest_tc_cleanup(void)
44+
{
45+
return RT_EOK;
46+
}
47+
48+
static void testcase(void)
49+
{
50+
/* Test unique_ptr basic operations */
51+
UTEST_UNIT_RUN(test_unique_ptr);
52+
/* Test shared_ptr basic operations */
53+
UTEST_UNIT_RUN(test_shared_ptr);
54+
}
55+
UTEST_TC_EXPORT(testcase, "testcases.cpp11.smartptr_tc", utest_tc_init, utest_tc_cleanup, 10);

0 commit comments

Comments
 (0)