Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/***********************************************************************************************************************************
Test Object Helper Macros
***********************************************************************************************************************************/
#include "common/macro.h"
 
/***********************************************************************************************************************************
TestObject Types
***********************************************************************************************************************************/
typedef struct TestObject
{
    bool data;                                                      // Test data
} TestObject;
 
/***********************************************************************************************************************************
Standard object methods
***********************************************************************************************************************************/
static TestObject *
testObjectMove(TestObject *this, MemContext *parentNew)
{
    return objMove(this, parentNew);
}
 
static void
testObjectFree(TestObject *this)
{
    objFree(this);
}
 
/**********************************************************************************************************************************/
static TestObject *
testObjectNew(void)
{
    OBJ_NEW_BEGIN(TestObject, .childQty = 1)
    {
        *this = (TestObject)
        {
            .data = true,
        };
    }
    OBJ_NEW_END();
 
    return this;
}
 
/***********************************************************************************************************************************
Test Run
***********************************************************************************************************************************/
static void
testRun(void)
{
    FUNCTION_HARNESS_VOID();
 
    // *****************************************************************************************************************************
    if (testBegin("OBJECT_DEFINE*()"))
    {
        TEST_TITLE("object with mem context and allocation together");
 
        TestObject *testObject = NULL;
 
        MEM_CONTEXT_TEMP_BEGIN()
        {
            TEST_ASSIGN(testObject, testObjectNew(), "new test object");
            TEST_RESULT_VOID(testObjectMove(testObject, memContextPrior()), "move object to parent context");
            TEST_RESULT_VOID(testObjectMove(NULL, memContextPrior()), "move null object");
        }
        MEM_CONTEXT_TEMP_END();
 
        TEST_RESULT_PTR(objMemContext(testObject), memContextFromAllocExtra(testObject), "mem context");
        TEST_RESULT_VOID(testObjectFree(testObject), "free object");
        TEST_RESULT_VOID(testObjectFree(NULL), "free null object");
 
        // -------------------------------------------------------------------------------------------------------------------------
        TEST_TITLE("move object to interface");
 
        TestObject *testInterface = NULL;
 
        TEST_ASSIGN(testInterface, testObjectNew(), "new interface object");
        TEST_ASSIGN(testObject, testObjectNew(), "new test object");
 
        // Only one of these can success since the interface only accepts one child
        TEST_RESULT_VOID(objMoveToInterface(testObject, testInterface, objMemContext(testObject)), "no move to interface");
        TEST_RESULT_VOID(objMoveToInterface(testObject, testInterface, memContextCurrent()), "move to interface");
    }
 
    FUNCTION_HARNESS_RETURN_VOID();
}