Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx_testframework_t.h File Reference
#include <functional>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>
#include "ssgx_utils_t.h"

Go to the source code of this file.

Classes

struct  ssgx::testframework_t::InternalAssertionException
 Internal exceptions thrown by the test framework. More...
 
class  ssgx::testframework_t::TestManager
 Manages registration and execution of test cases grouped into suites. More...
 

Namespaces

namespace  ssgx
 
namespace  ssgx::testframework_t
 This module is a testing framework designed for test cases within the enclave.
 

Macros

#define ANSI_ESCAPE_CODE_RESET   "\033[0m"
 
#define ANSI_ESCAPE_CODE_RED   "\033[31m"
 
#define ANSI_ESCAPE_CODE_GREEN   "\033[32m"
 
#define ANSI_ESCAPE_CODE_YELLOW   "\033[33m"
 
#define ANSI_ESCAPE_CODE_BLUE   "\033[34m"
 
#define TEST(suiteName, testName)
 
#define ASSERT_TRUE(expr)
 
#define ASSERT_FALSE(expr)
 
#define ASSERT_EQ(a, b)
 
#define ASSERT_NE(a, b)
 
#define ASSERT_LT(a, b)
 
#define ASSERT_LE(a, b)
 
#define ASSERT_GT(a, b)
 
#define ASSERT_GE(a, b)
 
#define ASSERT_NEAR(a, b, abs_error)
 
#define ASSERT_STR_EQ(a, b)
 
#define ASSERT_STR_NE(a, b)
 
#define ASSERT_BYTES_EQ(a, b)
 
#define ASSERT_BYTES_NE(a, b)
 
#define ASSERT_MEM_EQ(ptr1, len1, ptr2, len2)
 
#define ASSERT_MEM_NE(ptr1, len1, ptr2, len2)
 
#define ASSERT_THROW(expr, exception_type)
 
#define ASSERT_NO_THROW(expr)
 
#define SUCCEED()
 

Macro Definition Documentation

◆ ANSI_ESCAPE_CODE_BLUE

#define ANSI_ESCAPE_CODE_BLUE   "\033[34m"

◆ ANSI_ESCAPE_CODE_GREEN

#define ANSI_ESCAPE_CODE_GREEN   "\033[32m"

◆ ANSI_ESCAPE_CODE_RED

#define ANSI_ESCAPE_CODE_RED   "\033[31m"

◆ ANSI_ESCAPE_CODE_RESET

#define ANSI_ESCAPE_CODE_RESET   "\033[0m"

◆ ANSI_ESCAPE_CODE_YELLOW

#define ANSI_ESCAPE_CODE_YELLOW   "\033[33m"

◆ ASSERT_BYTES_EQ

#define ASSERT_BYTES_EQ ( a,
b )
Value:
do { \
if ((a).size() != (b).size() || std::memcmp((a).data(), (b).data(), (a).size()) != 0) { \
"ASSERT_BYTES_EQ failed: \"" + std::string((a).begin(), (a).end()) + "\" != \"" + \
std::string((b).begin(), (b).end()) + "\"", \
__FILE__, __LINE__, __func__); \
} \
} while (0)
Internal exceptions thrown by the test framework.
Definition ssgx_testframework_t.h:29

◆ ASSERT_BYTES_NE

#define ASSERT_BYTES_NE ( a,
b )
Value:
do { \
if ((a).size() == (b).size() && std::memcmp((a).data(), (b).data(), (a).size()) == 0) { \
"ASSERT_BYTES_NE failed: \"" + std::string((a).begin(), (a).end()) + "\" == \"" + \
std::string((b).begin(), (b).end()) + "\"", \
__FILE__, __LINE__, __func__); \
} \
} while (0)

◆ ASSERT_EQ

#define ASSERT_EQ ( a,
b )
Value:
do { \
if (!((a) == (b))) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_EQ failed: " #a " == " #b, __FILE__, \
__LINE__, __func__); \
} \
} while (0)

◆ ASSERT_FALSE

#define ASSERT_FALSE ( expr)
Value:
do { \
if ((expr)) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_FALSE failed: " #expr, __FILE__, __LINE__, \
__func__); \
} \
} while (0)

◆ ASSERT_GE

#define ASSERT_GE ( a,
b )
Value:
do { \
if (!((a) >= (b))) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_GE failed: " #a " >= " #b, __FILE__, \
__LINE__, __func__); \
} \
} while (0)

◆ ASSERT_GT

#define ASSERT_GT ( a,
b )
Value:
do { \
if (!((a) > (b))) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_GT failed: " #a " > " #b, __FILE__, \
__LINE__, __func__); \
} \
} while (0)

◆ ASSERT_LE

#define ASSERT_LE ( a,
b )
Value:
do { \
if (!((a) <= (b))) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_LE failed: " #a " <= " #b, __FILE__, \
__LINE__, __func__); \
} \
} while (0)

◆ ASSERT_LT

#define ASSERT_LT ( a,
b )
Value:
do { \
if (!((a) < (b))) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_LT failed: " #a " < " #b, __FILE__, \
__LINE__, __func__); \
} \
} while (0)

◆ ASSERT_MEM_EQ

#define ASSERT_MEM_EQ ( ptr1,
len1,
ptr2,
len2 )
Value:
do { \
if ((len1) != (len2)) { \
"ASSERT_MEM_EQ failed: Memory blocks have different lengths", __FILE__, __LINE__, __func__); \
} \
if (std::memcmp((ptr1), (ptr2), (len1)) != 0) { \
"ASSERT_MEM_EQ failed: Memory blocks are not equal", __FILE__, __LINE__, __func__); \
} \
} while (0)

◆ ASSERT_MEM_NE

#define ASSERT_MEM_NE ( ptr1,
len1,
ptr2,
len2 )
Value:
do { \
if ((len1) == (len2) && std::memcmp((ptr1), (ptr2), (len1)) == 0) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_MEM_NE failed: Memory blocks are equal", \
__FILE__, __LINE__, __func__); \
} \
} while (0)

◆ ASSERT_NE

#define ASSERT_NE ( a,
b )
Value:
do { \
if (!((a) != (b))) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_NE failed: " #a " != " #b, __FILE__, \
__LINE__, __func__); \
} \
} while (0)

◆ ASSERT_NEAR

#define ASSERT_NEAR ( a,
b,
abs_error )
Value:
do { \
if (std::abs((a) - (b)) > abs_error) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_NEAR failed: " #a " ~= " #b, __FILE__, \
__LINE__, __func__); \
} \
} while (0)

◆ ASSERT_NO_THROW

#define ASSERT_NO_THROW ( expr)
Value:
do { \
try { \
expr; \
} catch (...) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_NO_THROW failed: Exception thrown", \
__FILE__, __LINE__, __func__); \
} \
} while (0)

◆ ASSERT_STR_EQ

#define ASSERT_STR_EQ ( a,
b )
Value:
do { \
if (std::string(a) != std::string(b)) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_STR_EQ failed: \"" + std::string(a) + \
"\" != \"" + std::string(b) + "\"", \
__FILE__, __LINE__, __func__); \
} \
} while (0)

◆ ASSERT_STR_NE

#define ASSERT_STR_NE ( a,
b )
Value:
do { \
if (std::string(a) == std::string(b)) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_STR_NE failed: \"" + std::string(a) + \
"\" == \"" + std::string(b) + "\"", \
__FILE__, __LINE__, __func__); \
} \
} while (0)

◆ ASSERT_THROW

#define ASSERT_THROW ( expr,
exception_type )
Value:
do { \
try { \
expr; \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_THROW failed: No exception thrown", \
__FILE__, __LINE__, __func__); \
} catch (const exception_type&) { \
} catch (...) { \
"ASSERT_THROW failed: Wrong exception type thrown", __FILE__, __LINE__, __func__); \
} \
} while (0)

◆ ASSERT_TRUE

#define ASSERT_TRUE ( expr)
Value:
do { \
if (!(expr)) { \
throw ssgx::testframework_t::InternalAssertionException("ASSERT_TRUE failed: " #expr, __FILE__, __LINE__, \
__func__); \
} \
} while (0)

◆ SUCCEED

#define SUCCEED ( )
Value:
do { \
ssgx::utils_t::Printf(ANSI_ESCAPE_CODE_GREEN "[SUCCEED]" ANSI_ESCAPE_CODE_RESET \
" %s:%d in %s()\n", __FILE__, __LINE__, __func__); \
} while (0)
#define ANSI_ESCAPE_CODE_GREEN
Definition ssgx_testframework_t.h:22
#define ANSI_ESCAPE_CODE_RESET
Definition ssgx_testframework_t.h:20

◆ TEST

#define TEST ( suiteName,
testName )
Value:
void suiteName##_##testName(); \
struct suiteName##_##testName##_Register { \
suiteName##_##testName##_Register() { \
ssgx::testframework_t::TestManager::AddTest(#suiteName, #testName, suiteName##_##testName); \
} \
} suiteName##_##testName##_register; \
void suiteName##_##testName()