This source file includes following definitions.
- MinimalCTest
#ifdef __cplusplus
#error "This file should be compiled as C, not C++."
#endif
#include <stddef.h>
#include <string.h>
#include "mojo/public/c/system/core.h"
#include "mojo/public/c/system/async_waiter.h"
#include "mojo/public/c/system/macros.h"
#define STRINGIFY(x) #x
#define STRINGIFY2(x) STRINGIFY(x)
#define FAILURE(message) \
__FILE__ "(" STRINGIFY2(__LINE__) "): Failure: " message
#define EXPECT_EQ(a, b) \
do { \
if ((a) != (b)) \
return FAILURE(STRINGIFY(a) " != " STRINGIFY(b) " (expected ==)"); \
} while (0)
#define EXPECT_NE(a, b) \
do { \
if ((a) == (b)) \
return FAILURE(STRINGIFY(a) " == " STRINGIFY(b) " (expected !=)"); \
} while (0)
const char* MinimalCTest(void) {
MojoTimeTicks ticks;
MojoHandle handle0, handle1;
MojoWaitFlags wait_flags;
const char kHello[] = "hello";
char buffer[200] = { 0 };
uint32_t num_bytes;
ticks = MojoGetTimeTicksNow();
EXPECT_NE(ticks, 0);
handle0 = MOJO_HANDLE_INVALID;
EXPECT_NE(MOJO_RESULT_OK, MojoClose(handle0));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoWait(handle0, MOJO_WAIT_FLAG_EVERYTHING,
MOJO_DEADLINE_INDEFINITE));
handle1 = MOJO_HANDLE_INVALID;
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(&handle0, &handle1));
wait_flags = MOJO_WAIT_FLAG_READABLE;
EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
MojoWaitMany(&handle0, &wait_flags, 1, 1));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(handle0, kHello, (uint32_t) sizeof(kHello), NULL,
0u, MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK,
MojoWait(handle1, MOJO_WAIT_FLAG_READABLE,
MOJO_DEADLINE_INDEFINITE));
num_bytes = (uint32_t) sizeof(buffer);
EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(handle1, buffer, &num_bytes, NULL, NULL,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ((uint32_t) sizeof(kHello), num_bytes);
EXPECT_EQ(0, memcmp(buffer, kHello, sizeof(kHello)));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle0));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle1));
return NULL;
}