Skip to content

Commit 098e853

Browse files
committed
[utest][cpp]add cpp-lambda testcase.
1 parent 1d2b9cc commit 098e853

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
14+
/**
15+
* @brief Test basic lambda expression.
16+
*/
17+
static void test_lambda_basic(void)
18+
{
19+
auto lambda = []() { return 42; };
20+
if (lambda() != 42)
21+
{
22+
uassert_false(true);
23+
}
24+
uassert_true(true);
25+
}
26+
27+
/**
28+
* @brief Test lambda with capture.
29+
*/
30+
static void test_lambda_capture(void)
31+
{
32+
int x = 10;
33+
auto lambda = [x]() { return x * 2; };
34+
if (lambda() != 20)
35+
{
36+
uassert_false(true);
37+
}
38+
uassert_true(true);
39+
}
40+
41+
static rt_err_t utest_tc_init(void)
42+
{
43+
return RT_EOK;
44+
}
45+
46+
static rt_err_t utest_tc_cleanup(void)
47+
{
48+
return RT_EOK;
49+
}
50+
51+
static void testcase(void)
52+
{
53+
/* Test basic lambda expression */
54+
UTEST_UNIT_RUN(test_lambda_basic);
55+
/* Test lambda with capture */
56+
UTEST_UNIT_RUN(test_lambda_capture);
57+
}
58+
UTEST_TC_EXPORT(testcase, "testcases.cpp11.lambda_tc", utest_tc_init, utest_tc_cleanup, 10);

0 commit comments

Comments
 (0)