Debian Codegraph @

hic/tests/test_hic_dummy.cc

raw
1 /*
2 * (C) Copyright 2024- ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10 #include <functional>
11 #include <iostream>
12 #include <utility>
13 #include <vector>
14
15 #include "hic/hic.h"
16
17 int test_throw() {
18 std::cout << "--- " << __FUNCTION__ << std::endl;
19 // For the dummy backend we expect to have an error thrown when used
20 void* p;
21 try {
22 std::ignore = hicMalloc(&p, 8);
23 std::ignore = hicFree(p);
24 }
25 catch (std::runtime_error& e) {
26 std::string expected_message = "hicMalloc is using the dummy backend and should not be called";
27 if (e.what() == expected_message) {
28 std::cout << "--- " << __FUNCTION__ << " SUCCEEDED " << std::endl;
29 return 0; // success
30 }
31 }
32 std::cout << "--- " << __FUNCTION__ << " SUCCEEDED " << std::endl;
33 return 1; // fail
34 }
35
36 std::vector<std::function<int()>> tests = {test_throw};
37
38 int main(int /*argc*/, char** /*argv*/) {
39 int error = 0;
40 for (auto& test : tests) {
41 error += test();
42 }
43 return error;
44 }