zpp
Zephyr C++20 Framework
main.cpp File Reference
#include <zephyr/ztest.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/kernel.h>
#include <string.h>
#include <zpp.hpp>
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

 ZTEST_SUITE (test_zpp_result, NULL, NULL, NULL, NULL, NULL)
 
 ZTEST (test_zpp_result, test_result)
 

Function Documentation

◆ ZTEST()

ZTEST ( test_zpp_result  ,
test_result   
)

Definition at line 39 of file main.cpp.

40 {
44 
45  zassert_true(!res_a, "res_a should be false\n");
46  zassert_false(res_b, "res_b should be false\n");
47  zassert_true(res_c == false, "res_c should be false\n");
48 
50 
51  zassert_true(res_a == false, "res_a should be false\n");
52 
53  res_a = 12345;
54 
55  zassert_true(res_a == true, "res_a should be true\n");
56  zassert_true(res_a.value() == 12345, "res_a.value() should be 12345\n");
57 
58  auto res_d = res_a;
59  zassert_true(res_d == true, "res_d should be true\n");
60  zassert_true(res_d.value() == 12345, "res_d.value() should be 12345\n");
61 
62  res_d.assign_error(zpp::error_code::k_already);
63  zassert_false(res_d, "res_d should be false\n");
64  zassert_true(res_d.error() == zpp::error_code::k_already, "res_d should hold zpp::error_code::k_already");
65 
67  zassert_false(res_e, "res_d should be true\n");
68 
69  res_e.assign_value();
70  zassert_true(!!res_e, "res_d should be true\n");
71 
72  res_e = zpp::error_result(0);
73  zassert_true(res_e.error() == 0, "res_d should hold 0");
74 
76  zassert_false(res_f, "res_f should be false\n");
77 
78  zpp::result<void, ErrorData> res_g(zpp::error_result(ErrorData(13)));
79  zassert_false(res_g, "res_g should be false\n");
80 
82  zassert_false(res_h, "res_h should be false\n");
83 
84 }
helper class for error result
Definition: result.hpp:25
result class
Definition: result.hpp:89
void assign_value(const T_Ok &v) noexcept
Definition: result.hpp:197
T_Ok & value() noexcept
return a reference to the OK value
Definition: result.hpp:327
T_Error & error() noexcept
return a reference to the OK value
Definition: result.hpp:358
@ k_inval
Invalid argument.
@ k_already
Operation already in progress.

References zpp::result< T_Ok, T_Error >::assign_value(), zpp::result< T_Ok, T_Error >::error(), zpp::k_already, zpp::k_inval, and zpp::result< T_Ok, T_Error >::value().

◆ ZTEST_SUITE()

ZTEST_SUITE ( test_zpp_result  ,
NULL  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)