少年修仙传客户端基础资源
hch
2024-04-11 4c71d74b77c9eb62a0323698c9a0db3b641a917e
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#if ENABLE_UNIT_TESTS
 
#include "UnitTest++.h"
#include "../Semaphore-c-api.h"
#include "../../Semaphore.h"
#include "../../Event.h"
#include "../../Thread.h"
 
SUITE(Semaphore)
{
    struct SemaphoreFixture
    {
        SemaphoreFixture()
        {
            il2cpp::os::Thread::Init();
            semaphore = UnityPalSemaphoreNew(0, 1);
            unblockedThreadEvent = new il2cpp::os::Event();
            unblockedThreadCount = 0;
        }
 
        ~SemaphoreFixture()
        {
            UnityPalSemaphoreDelete(semaphore);
        }
 
        UnityPalSemaphore* semaphore;
        il2cpp::os::Event* unblockedThreadEvent;
        int unblockedThreadCount;
 
        static void WaitForSemaphoreAndIncrementCounter(void* arg)
        {
            SemaphoreFixture* data = static_cast<SemaphoreFixture*>(arg);
            UnityPalSemaphoreWait(data->semaphore, false);
            data->unblockedThreadCount++;
            data->unblockedThreadEvent->Set();
        }
    };
 
    TEST_FIXTURE(SemaphoreFixture, CanCreateASemaphore)
    {
        CHECK_NOT_NULL(semaphore);
    }
 
    TEST_FIXTURE(SemaphoreFixture, VerifyThatPostingASemaphoreAGivenNumberOfTimesReturnsThePreviousCount)
    {
        int32_t actualPreviousCount = 0;
        UnityPalSemaphorePost(semaphore, 2, &actualPreviousCount);
        CHECK_EQUAL(0, actualPreviousCount);
    }
 
    TEST_FIXTURE(SemaphoreFixture, VerifyThatPostWithMultipleThreadsWaitingUnblocksOnlyOneThread)
    {
        // Create two threads which each increment the counter once.
        il2cpp::os::Thread thread1;
        thread1.Run(WaitForSemaphoreAndIncrementCounter, this);
 
        il2cpp::os::Thread thread2;
        thread2.Run(WaitForSemaphoreAndIncrementCounter, this);
 
        UnityPalSemaphorePost(semaphore, 1, NULL);
 
        // Let one thread increment and wait for it.
        unblockedThreadEvent->Wait();
 
        CHECK_EQUAL(1, unblockedThreadCount);
 
        // Let the other thread increment and wait for it so we can exit the test cleanly.
        UnityPalSemaphorePost(semaphore, 1, NULL);
        unblockedThreadEvent->Wait();
 
        thread1.Join();
        thread2.Join();
    }
 
    struct SemaphoreHandleFixture
    {
        SemaphoreHandleFixture()
        {
            il2cpp::os::Thread::Init();
            semaphore = UnityPalSemaphoreNew(0, 1);
            semaphoreHandle = UnityPalSemaphoreHandleNew(semaphore);
            unblockedThreadEvent = new il2cpp::os::Event();
            unblockedThreadCount = 0;
        }
 
        ~SemaphoreHandleFixture()
        {
            UnityPalSemaphoreHandleDelete(semaphoreHandle);
        }
 
        UnityPalSemaphore* semaphore;
        UnityPalSemaphoreHandle* semaphoreHandle;
        il2cpp::os::Event* unblockedThreadEvent;
        int unblockedThreadCount;
 
        static void WaitForSemaphoreAndIncrementCounter(void* arg)
        {
            SemaphoreHandleFixture* data = static_cast<SemaphoreHandleFixture*>(arg);
            UnityPalSemaphoreHandleWait(data->semaphoreHandle);
            data->unblockedThreadCount++;
            data->unblockedThreadEvent->Set();
        }
    };
 
    TEST_FIXTURE(SemaphoreHandleFixture, CanCreateASemaphoreHandle)
    {
        CHECK_NOT_NULL(semaphoreHandle);
    }
 
    TEST_FIXTURE(SemaphoreHandleFixture, VerifyThatPostingASemaphoreHandleAGivenNumberOfTimesReturnsThePreviousCount)
    {
        int32_t actualPreviousCount = 0;
        UnityPalSemaphoreHandleSignal(semaphoreHandle);
        CHECK_EQUAL(0, actualPreviousCount);
    }
 
    TEST_FIXTURE(SemaphoreHandleFixture, VerifyThatPostHandleWithMultipleThreadsWaitingUnblocksOnlyOneThread)
    {
        // Create two threads which each increment the counter once.
        il2cpp::os::Thread thread1;
        thread1.Run(WaitForSemaphoreAndIncrementCounter, this);
 
        il2cpp::os::Thread thread2;
        thread2.Run(WaitForSemaphoreAndIncrementCounter, this);
 
        UnityPalSemaphoreHandleSignal(semaphoreHandle);
 
        // Let one thread increment and wait for it.
        unblockedThreadEvent->Wait();
 
        CHECK_EQUAL(1, unblockedThreadCount);
 
        // Let the other thread increment and wait for it so we can exit the test cleanly.
        UnityPalSemaphoreHandleSignal(semaphoreHandle);
        unblockedThreadEvent->Wait();
 
        thread1.Join();
        thread2.Join();
    }
}
 
#endif // ENABLE_UNIT_TESTS