コード例 #1
0
int TestCase_Comm_PacketHeaderParts::Run(int argc, char *argv[])
{
    LLBC_PrintLine("comm/PacketeHeaderParts test:");

    int serialNo = 0;
    this->TestOne<sint8>(serialNo++, 'a', "sint8");
    this->TestOne<uint8>(serialNo++, 8, "uint8");
    this->TestOne<sint16>(serialNo++, -16, "sint16");
    this->TestOne<uint16>(serialNo++, 16, "uint16");
    this->TestOne<sint32>(serialNo++, -32, "sint32");
    this->TestOne<uint32>(serialNo++, 32, "uint32");
    this->TestOne<sint64>(serialNo++, -64, "sint64");
    this->TestOne<uint64>(serialNo++, 64, "uint64");
    this->TestOne<float>(serialNo++, 1.618f, "float");
    this->TestOne<double>(serialNo++, 8.161, "double");
    this->TestOne<const char *>(serialNo++, "Hello World!", "char *");
    this->TestOne<std::string>(serialNo++, "Hello std::string!", "std::string");
    this->TestOne<LLBC_String>(serialNo++, "Hello LLBC_String!", "LLBC_String");

    this->TestSetToPacket();

    LLBC_PrintLine("Press any key to continue...");
    getchar();

    return 0;
}
コード例 #2
0
void TestCase_Com_DataType::StringSplitTest(const LLBC_String &str, size_t maxSplit, const LLBC_String &sep)
{
    LLBC_PrintLine("Will split string(maxSplit: %ld, sep: %s): %s", maxSplit, sep.c_str(), str.c_str());
    std::vector<LLBC_String> splitted = str.split(sep, maxSplit);
    LLBC_PrintLine("Split use separator:., size: %ld", splitted.size());
    for (size_t i = 0; i < splitted.size(); i++)
        LLBC_PrintLine("    \"%s\"", splitted[i].c_str());
}
コード例 #3
0
void TestCase_Com_DataType::StringStripTest()
{
    LLBC_PrintLine("Strip test:");
    LLBC_String str = "\t \t Hello World! \t \t";
    LLBC_PrintLine("Before strip, str: %s, len: %ld", str.c_str(), str.length());

    str.strip();
    LLBC_PrintLine("After strip, str: %s, len: %ld", str.c_str(), str.length());
}
コード例 #4
0
void TestCase_Com_DataType::StringFindReplaceTest()
{
    LLBC_PrintLine("FindReplace test:");

    LLBC_String str("Hello World, Hello World");
    LLBC_PrintLine("Before findreplace(), str: %s", str.c_str());
    str.findreplace("Hel", "HEL");
    LLBC_PrintLine("After findreplace(), str: %s", str.c_str());

    LLBC_PrintLine("\n");
}
コード例 #5
0
static int ThreadProc(void *arg)
{
    int threadIdx = static_cast<int>(reinterpret_cast<long>(arg));
    LLBC_PrintLine("thread %d startup", threadIdx);

    __g_tls.SetValue(new int);
    (*__g_tls) = threadIdx;
    for(int i = 0; i < 5000000; i ++)
        (*__g_tls) += 1;

    LLBC_PrintLine("thread [%d] tls value: %d", threadIdx, *__g_tls);

    return 0;
}
コード例 #6
0
int TestCase_Com_DataType::Run(int argc, char *argv[])
{
    LLBC_PrintLine("llbc library test case(datatype test):");

    // raw types test.
    this->RawTest();

    // string base test.
    this->StringBaseTest();

    // utf8 test.
    this->StringUTF8Test();

    // split test.
    this->StringSplitTest("com.packet.battle.");
    this->StringSplitTest("sys.io.stdout");
    this->StringSplitTest(".os.path");
    this->StringSplitTest(".");
    this->StringSplitTest("a.b.c.d.");
    this->StringSplitTest("a.b.c.d.", 3);
    this->StringSplitTest("X.Y.Z", -1, "/");

    // strip test.
    this->StringStripTest();

    getchar();

    return 0;
}
コード例 #7
0
bool TestCase_Core_File_File::GetXXXMethodsTest()
{
    LLBC_PrintLine("GetXXXMethods test:");

    // Open file as BinaryWrite mode for test.
    LLBC_File file(_testFileName, LLBC_FileMode::BinaryWrite);
    if (!file.IsOpened())
    {
        LLBC_PrintLine("Open file to test failed, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("File %s opened", _testFileName.c_str());

    // GetFileNo():
    LLBC_PrintLine("LLBC_File::GetFileNo(): %d", file.GetFileNo());
    // GetFileHandle():
    LLBC_PrintLine("LLBC_File::GetFileHandle()(FILE *): %p", file.GetFileHandle());
    // GetFileMode():
    LLBC_PrintLine("LLBC_File::GetFileMode(): %s", LLBC_FileMode::GetFileModeDesc(file.GetFileMode()).c_str());

    LLBC_PrintLine("");

    return true;
}
コード例 #8
0
int TestCase_Core_Thread_ThreadMgr::Run(int argc, char *argv[])
{
    LLBC_PrintLine("core/thread/ThreadManager test:");

    LLBC_PrintLine("Create threads:");
    LLBC_Handle groupHandle = LLBC_ThreadManagerSingleton->CreateThreads(2, &ThreadProc);
    if(groupHandle == LLBC_INVALID_HANDLE)
    {
        LLBC_PrintLine("Create threads failed, reason: %s", LLBC_FormatLastError());
    }
    else
    {
        LLBC_ThreadManager::Sleep(1000);
        LLBC_PrintLine("Create successed, group handle: %d, join it.", groupHandle);
        if(LLBC_ThreadManagerSingleton->WaitGroup(groupHandle) != LLBC_RTN_OK)
        {
            LLBC_PrintLine("Wait group failed, reason: %s", LLBC_FormatLastError());
        }
        else
        {
            LLBC_PrintLine("Wait group successed");
        }
    }

    LLBC_PrintLine("Press any key to continue ...");
    getchar();

    return 0;
}
コード例 #9
0
int TestCase_Com_Compiler::Run(int argc, char *argv[])
{
    LLBC_PrintLine("common/compiler test:");

    LLBC_String compInfo;
    compInfo.append_format("  Compiler Type: %d\n", LLBC_CUR_COMP)
        .append_format("  Compiler Version: %d\n", LLBC_COMP_VER)
        .append_format("  Major Version: %d\n", LLBC_COMP_MAJOR_VER)
        .append_format("  Minor Version: %d\n", LLBC_COMP_MINOR_VER)
        .append_format("  Patch Level: %d\n", LLBC_COMP_PATCH_LEVEL);

    LLBC_PrintLine("%s", compInfo.c_str());

    LLBC_PrintLine("Press any key to continue...");
    getchar();

    return LLBC_RTN_OK;
}
コード例 #10
0
static int ThreadProc(void *arg)
{
    LLBC_NativeThreadHandle nativeHandle = LLBC_ThreadManager::GetCurrentThread();
    LLBC_PrintLine("Hi, I'm thread %d", nativeHandle);

    LLBC_ThreadManager::Sleep(5000);

    return 0;
}
コード例 #11
0
int TestCase_Comm_LazyTask::Run(int argc, char *argv[])
{
    LLBC_PrintLine("service/lazy task test:");

    LLBC_IService *svc = LLBC_IService::Create(LLBC_IService::Normal);

    LazyClass *taskObj = LLBC_New(LazyClass);
    svc->Post(taskObj, &LazyClass::BeforeRun);

    svc->Start();

    LLBC_PrintLine("Press any key to exit...");
    getchar();

    LLBC_Delete(svc);
    LLBC_Delete(taskObj);

    return LLBC_OK;
}
コード例 #12
0
void TestCase_Com_DataType::StringBaseTest()
{
    LLBC_PrintLine("String base functions test:");

    LLBC_String testStr;
    testStr.format("%s", "hello world!");
    testStr.append_format("%s", "hello world!");
    LLBC_PrintLine("LLBC_String::format/append_format test: %s", testStr.c_str());

    LLBC_String testStr2;
    for(int i = 0; i < 1000; i++)
    {
        testStr.append("hello world!");
    }

    testStr2.append_format("%s", testStr.c_str());
    LLBC_PrintLine("LLBC_String:format large string test: %s", testStr2.c_str());

    // tolower/toupper test.
    testStr = "Hello WoRlD!";
    LLBC_PrintLine("'%s' to lower: '%s'", testStr.c_str(), testStr.tolower().c_str());
    LLBC_PrintLine("'%s' to upper: '%s'", testStr.c_str(), testStr.toupper().c_str());

    LLBC_PrintLine("\n");
}
コード例 #13
0
int TestCase_Core_Thread_Tls::Run(int argc, char *argv[])
{
    LLBC_PrintLine("core/thread/tls test");

    // Create threads.
    LLBC_NativeThreadHandle threads[__g_threadNum] = {LLBC_INVALID_NATIVE_THREAD_HANDLE};
    for(uint32 i = 0; i < __g_threadNum; i ++)
    {
        LLBC_CreateThread(&threads[i], &ThreadProc, reinterpret_cast<void *>(i));
    }

    // Join threads.
    for(uint32 i = 0; i < __g_threadNum; i ++)
    {
        LLBC_JoinThread(threads[i]);
    }

    LLBC_PrintLine("Press any key to continue ...");
    getchar();

    return 0;
}
コード例 #14
0
int TestCase_Core_File_File::Run(int argc, char *argv[])
{
    LLBC_PrintLine("Core/File test:");

    int retCode = LLBC_FAILED;
    do
    {
        if (!FileModeDescTest())
            break;

        if (!OpenCloseTest())
            break;

        if (!GetXXXMethodsTest())
            break;

        if (!ReadWriteTest())
            break;

        if (!FileAttributeTest())
            break;

        if (!CopyFileTest())
            break;

        if (!MoveFileTest())
            break;

        retCode = LLBC_OK;
    } while (0);

    LLBC_PrintLine("Press any key to continue...");
    getchar();

    return retCode;
}
コード例 #15
0
void TestCase_Core_File_File::PrintFileAttributes(const LLBC_FileAttributes &fileAttrs)
{
    LLBC_PrintLine("    Readable: %s", fileAttrs.readable ? "true" : "false");
    LLBC_PrintLine("    Writable: %s", fileAttrs.writable ? "true" : "false");
    LLBC_PrintLine("    Execable: %s", fileAttrs.execable ? "true" : "false");

    LLBC_PrintLine("    Is directory: %s", fileAttrs.isDirectory ? "true" : "false");

#if LLBC_TARGET_PLATFORM_WIN32
    const LLBC_Time createTime(fileAttrs.createTime);
    LLBC_PrintLine("    create time: %s", createTime.Format().c_str());
#else
    LLBC_PrintLine("    last change status time: %s",  LLBC_Time(fileAttrs.lastChangeStatusTime).Format().c_str());
#endif
    LLBC_PrintLine("    last modify time: %s", LLBC_Time(fileAttrs.lastModifyTime).Format().c_str());
    LLBC_PrintLine("    last access time: %s", LLBC_Time(fileAttrs.lastAccessTime).Format().c_str());
}
コード例 #16
0
void TestCase_Com_DataType::StringUTF8Test()
{
    LLBC_PrintLine("UTF-8 test:");

    LLBC_String utf8Str;
    utf8Str.append("\xef\xbb\xbf"); // Add bomb.
    LLBC_PrintLine("utf8Str exist bomb? %s", utf8Str.has_utf8_bomb() ? "true" : "false");

    // 0000000: e4bd a0e5 a5bd e4b8 96e7 958c 4865 6c6c  ............Hell
    // 0000010: 6f20 576f 726c 640a                      o World.
    utf8Str.append(1, (char)0xe4).append(1, (char)0xbd).append(1, (char)0xa0);
    utf8Str.append(1, (char)0xe5).append(1, (char)0xa5).append(1, (char)0xbd);
    utf8Str.append(1, (char)0xe4).append(1, (char)0xb8).append(1, (char)0x96);
    utf8Str.append(1, (char)0xe7).append(1, (char)0x95).append(1, (char)0x8c);
    utf8Str.append("Hello World");
    LLBC_PrintLine("When add string, len: %ld, utf8 len: %ld", utf8Str.length(), utf8Str.length_with_utf8());

    // split_utf8_string().
    std::vector<LLBC_String> utf8Vec;
    utf8Str.split_utf8_string(1, utf8Vec);
    LLBC_PrintLine("Split utf8 string done, first str size: %ld, second str size: %ld", utf8Vec[0].length(), utf8Vec[1].length());
    utf8Str.split_utf8_string(-1, utf8Vec);
    LLBC_PrintLine("Reverse split utf8 string done, first str size: %ld, second str size: %ld", utf8Vec[0].length(), utf8Vec[1].length());

    // trim/add bomb.
    utf8Str.trim_utf8_bomb();
    utf8Str.add_utf8_bomb();

    // scatter_utf8_string().
    utf8Str.scatter_utf8_string(utf8Vec, 0);
    utf8Str.scatter_utf8_string(utf8Vec, 1);
    utf8Str.scatter_utf8_string(utf8Vec, 2);
    utf8Str.scatter_utf8_string(utf8Vec, 3);
    LLBC_PrintLine("After scatter utf8 string, vector size: %ld", utf8Vec.size());

    LLBC_PrintLine("\n");
}
コード例 #17
0
bool TestCase_Core_File_File::OpenCloseTest()
{
    LLBC_PrintLine("Open/Close file test:");

    // Open/Close use BinaryRead mode.
    LLBC_String fileName = _testFileName;
    LLBC_PrintLine("Open file use constructor method(BinaryRead): %s", fileName.c_str());
    LLBC_File file(fileName, LLBC_FileMode::BinaryRead);
    if (file.IsOpened())
    {
        LLBC_PrintLine("File opened, test failed!!!");
        return false;
    }

    LLBC_PrintLine("File open failed, error: %s", LLBC_FormatLastError());

    // Open/Close use BinaryWrite mode.
    LLBC_PrintLine("Open file use constructor method(BinaryWrite): %s", fileName.c_str());
    LLBC_File file2(fileName, LLBC_FileMode::BinaryWrite);
    if (!file2.IsOpened())
    {
        LLBC_PrintLine("File not open, error: %s, test failed!!!", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("File open success, close it");
    file2.Close();

    // Open/Close file use Open method.
    LLBC_PrintLine("Open file use Open() method(BinaryRead): %s", fileName.c_str());
    LLBC_File file3;
    if (file3.Open(fileName, LLBC_FileMode::BinaryRead) != 0)
    {
        LLBC_PrintLine("File open failed, error: %s, test failed", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("Open successful, reopen it(LastestMode):");
    if (file3.ReOpen(LLBC_FileMode::LastestMode) != 0)
    {
        LLBC_PrintLine("Reopen file failed, error: %s", LLBC_FormatLastError());
        return false;
    }
    else
    {
        LLBC_PrintLine("Reopen success, mode: %s", LLBC_FileMode::GetFileModeDesc(file3.GetFileMode()).c_str());
    }

    LLBC_PrintLine("Reopen successful, reopen again(BinaryWrite):");
    if (file3.ReOpen(LLBC_FileMode::BinaryWrite) != 0)
    {
        LLBC_PrintLine("Reopen file failed, error: %s", LLBC_FormatLastError());
        return false;
    }

    file3.Close();

    // Final, delete test file.
    LLBC_PrintLine("Delete test file");
    if (LLBC_File::DeleteFile(fileName) != LLBC_OK)
    {
        LLBC_PrintLine("Delete file failed, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("");

    return true;
}
コード例 #18
0
int TestCase_Core_Utils_Coder::Run(int argc, char *argv[])
{
    LLBC_PrintLine("Util_Coder test:");

    // Get machine endian type.
    LLBC_PrintLine("machine endian type: %s", 
        LLBC_Endian::Type2Str( LLBC_GetMachineEndianType()));
    LLBC_PrintLine("");

    // Endian type -> Endian describe test.
    LLBC_PrintLine("LLBC_Endian::BigEndian describe: %s", 
        LLBC_Endian::Type2Str(LLBC_Endian::BigEndian));
    LLBC_PrintLine("LLBC_Endian::LittleEndian describe: %s",
        LLBC_Endian::Type2Str(LLBC_Endian::LittleEndian));
    LLBC_PrintLine("LLBC_Endian::UnknownEndian describe: %s",
        LLBC_Endian::Type2Str(LLBC_Endian::UnknownEndian));
    LLBC_PrintLine("LLBC_Endian::UnknownEndian + 300 describe: %s",
        LLBC_Endian::Type2Str(LLBC_Endian::UnknownEndian + 300));
    LLBC_PrintLine("");

    // Endian describe -> Endian type test.
    LLBC_PrintLine("'big endian' type: %d", LLBC_Endian::Str2Type("big endian"));
    LLBC_PrintLine("'little endian' type: %d", LLBC_Endian::Str2Type("little endian"));
    LLBC_PrintLine("'unknown endian' type: %d", LLBC_Endian::Str2Type("unknown type"));
    LLBC_PrintLine("'hello' type: %d", LLBC_Endian::Str2Type("hello"));
    LLBC_PrintLine("");

    // Test host <-> net.
    int data = 0x01020304;
    LLBC_PrintLine("host to net test, host: 0x%08x, net: 0x%08x",
        data, LLBC_Host2Net2(data));
    LLBC_Host2Net(data);
    LLBC_PrintLine("net to host test, net: 0x%08x, host: 0x%08x",
        data, LLBC_Net2Host2(data));
    LLBC_PrintLine("");

    LLBC_PrintLine("Press any key to continue ...");
    getchar();

    return 0;
}
コード例 #19
0
bool TestCase_Core_File_File::FileModeDescTest()
{
    LLBC_PrintLine("LLBC_FileMode describe test:");
    LLBC_PrintLine("LLBC_FileMode::TextRead(%08x): %s", LLBC_FileMode::TextRead, LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::TextRead).c_str());
    LLBC_PrintLine("LLBC_FileMode::TextWrite(%08x): %s", LLBC_FileMode::TextWrite, LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::TextWrite).c_str());
    LLBC_PrintLine("LLBC_FileMode::TextReadWrite(%08x): %s", LLBC_FileMode::TextReadWrite, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::TextReadWrite).c_str());
    LLBC_PrintLine("LLBC_FileMode::TextAppendWrite(%08x): %s", LLBC_FileMode::TextAppendWrite, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::TextAppendWrite).c_str());
    LLBC_PrintLine("LLBC_FileMode::TextAppendReadWrite(%08x): %s", LLBC_FileMode::TextAppendReadWrite, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::TextAppendReadWrite).c_str());

    LLBC_PrintLine("LLBC_FileMode::BinaryRead(%08x): %s", LLBC_FileMode::BinaryRead, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::BinaryRead).c_str());
    LLBC_PrintLine("LLBC_FileMode::BinaryWrite(%08x): %s", LLBC_FileMode::BinaryWrite, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::BinaryWrite).c_str());
    LLBC_PrintLine("LLBC_FileMode::BinaryReadWrite(%08x): %s", LLBC_FileMode::BinaryReadWrite, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::BinaryReadWrite).c_str());
    LLBC_PrintLine("LLBC_FileMode::BinaryAppendWrite(%08x): %s", LLBC_FileMode::BinaryAppendWrite, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::BinaryAppendWrite).c_str());
    LLBC_PrintLine("LLBC_FileMode::BinaryAppendReadWrite(%08x): %s", LLBC_FileMode::BinaryAppendReadWrite, 
        LLBC_FileMode::GetFileModeDesc(LLBC_FileMode::BinaryAppendReadWrite).c_str());

    LLBC_PrintLine("");

    return true;
}
コード例 #20
0
bool TestCase_Core_File_File::FileAttributeTest()
{
    LLBC_PrintLine("file attribute about test:");
    LLBC_File file(_testFileName, LLBC_FileMode::BinaryRead);
    if (!file.IsOpened())
    {
        LLBC_PrintLine("Open file to test failed, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_FileAttributes fileAttrs;
    if (file.GetFileAttributes(fileAttrs) != LLBC_OK)
    {
        LLBC_PrintLine("Failed to get file attributes, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("File %s attributes got, print it: ", _testFileName.c_str());
    PrintFileAttributes(fileAttrs);

    // Test directory attributes:
    if (LLBC_File::GetFileAttributes(".", fileAttrs) != LLBC_OK)
    {
        LLBC_PrintLine("Failed to get file attributes, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("File %s attributes got, print it: ", ".");
    PrintFileAttributes(fileAttrs);

    file.Close();

    LLBC_PrintLine("Touch file test, file: %s", _testFileName.c_str());
    LLBC_PrintLine("Touch all times to now:");
    if (LLBC_File::TouchFile(_testFileName, true, NULL, true, NULL) != LLBC_OK)
    {
        LLBC_PrintLine("Failed to touch file: %s, error: %s", _testFileName.c_str(), LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("Touched, attributes:");
    LLBC_File::GetFileAttributes(_testFileName, fileAttrs);
    PrintFileAttributes(fileAttrs);

    LLBC_PrintLine("Sleep 2 seconds...");
    LLBC_Sleep(2000);
    LLBC_PrintLine("Touch last access time to now");
    LLBC_File::TouchFile(_testFileName, true, NULL, false, NULL);
    LLBC_PrintLine("Touched, attributes:");
    LLBC_File::GetFileAttributes(_testFileName, fileAttrs);
    PrintFileAttributes(fileAttrs);

    LLBC_PrintLine("Sleep 2 seconds...");
    LLBC_Sleep(2000);
    LLBC_PrintLine("Touch last modify time to now");
    LLBC_File::TouchFile(_testFileName, false, NULL, true, NULL);
    LLBC_PrintLine("Touched, attributes:");
    LLBC_File::GetFileAttributes(_testFileName, fileAttrs);
    PrintFileAttributes(fileAttrs);

    LLBC_PrintLine("");

    return true;
}
コード例 #21
0
bool TestCase_Core_File_File::MoveFileTest()
{
    LLBC_PrintLine("Move file test:");

    const LLBC_String moveFileName = _testFileName + ".move";
    LLBC_File file(_testFileName, LLBC_FileMode::BinaryReadWrite);
    if (!file.IsOpened())
    {
        LLBC_PrintLine("Open test file[%s] failed, error: %s", _testFileName.c_str(), LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("test file[name: %s, will move] opened, write line string: Hello World!", _testFileName.c_str());
    file.WriteLine("Hello World");

    LLBC_PrintLine("Begin move(overlapped): %s ---> %s", _testFileName.c_str(), moveFileName.c_str());
    if (file.MoveFile(moveFileName, true) != LLBC_OK)
    {
        LLBC_PrintLine("Move file failed, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("Open the move file:");
    LLBC_File moveFile(moveFileName, LLBC_FileMode::BinaryRead);
    if (!moveFile.IsOpened())
    {
        LLBC_PrintLine("Failed to open move file, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("Move file opened, content: %s", moveFile.ReadToEnd().c_str());
    moveFile.Close();

    const LLBC_String copyFileName = _testFileName + ".copy";
    LLBC_File::CopyFile(moveFileName, copyFileName, true);
    LLBC_PrintLine("Copy move file and move again(don't overlapped): %s ---> %s", copyFileName.c_str(), copyFileName.c_str());
    if (LLBC_File::MoveFile(copyFileName, moveFileName, false) == LLBC_OK)
    {
        LLBC_PrintLine("Move success, failed. check your code!");
        LLBC_File::DeleteFile(copyFileName);
        LLBC_File::DeleteFile(moveFileName);

        return false;
    }
    else
    {
        LLBC_PrintLine("Move failed, error: %s, right!", LLBC_FormatLastError());
    }

    LLBC_PrintLine("Delete copy file and move file");
    LLBC_File::DeleteFile(copyFileName);
    LLBC_File::DeleteFile(moveFileName);

    LLBC_PrintLine("");

    return true;
}
コード例 #22
0
bool TestCase_Core_File_File::ReadWriteTest()
{
    LLBC_PrintLine("Read/Write test:");
    // Open file as BinaryWrite mode for test.
    LLBC_File file(_testFileName, LLBC_FileMode::BinaryReadWrite);
    if (!file.IsOpened())
    {
        LLBC_PrintLine("Open file to test failed, error: %s", LLBC_FormatLastError());
        return false;
    }

    LLBC_PrintLine("File %s opened", _testFileName.c_str());

    // Write raw data:
    LLBC_PrintLine("Write (bool)true, (bool)false, (sint8)-8, (uint8)8, (sint16)-16, (uint16)16, "
        "(sint32)-32, (uint32)32, (sint64)-64, (uint64)64, (float)3.14, (double)1.618");
    file.Write(true), file.Write(false);
    file.Write(static_cast<sint8>(-8)); file.Write(static_cast<uint8>(8));
    file.Write(static_cast<sint16>(-16)); file.Write(static_cast<uint16>(16));
    file.Write(static_cast<sint32>(-32)); file.Write(static_cast<uint32>(32));
    file.Write(static_cast<sint64>(-64)); file.Write(static_cast<uint64>(64));
    file.Write(static_cast<float>(3.14)); file.Write(static_cast<double>(1.618));

    // Seek file pointer to file begin.
    LLBC_PrintLine("Seek file pointer to begin.");
    file.Seek(LLBC_FileSeekOrigin::Begin, 0);

    // Read it
    bool trueVal, falseVal;
    file.Read(trueVal); file.Read(falseVal);
    sint8 sint8Val; uint8 uint8Val;
    file.Read(sint8Val); file.Read(uint8Val);
    sint16 sint16Val; uint16 uint16Val;
    file.Read(sint16Val); file.Read(uint16Val);
    sint32 sint32Val; uint32 uint32Val;
    file.Read(sint32Val); file.Read(uint32Val);
    sint64 sint64Val; uint64 uint64Val;
    file.Read(sint64Val); file.Read(uint64Val);
    float floatVal; double doubleVal;
    file.Read(floatVal); file.Read(doubleVal);
    LLBC_PrintLine("Read it: %s, %s, %d, %u, %d, %u, %d, %u, %lld, %llu, %f, %f",
        trueVal ? "true" : "false", falseVal ? "true" : "false",
        sint8Val, uint8Val, sint16Val, uint16Val, sint32Val, uint32Val,
        sint64Val, uint64Val, floatVal, doubleVal);

    LLBC_PrintLine("Seek(Current, -sizeof(double)), and read again the double value:");
    file.Seek(LLBC_FileSeekOrigin::Current, -8);
    doubleVal = 0.0; file.Read(doubleVal);
    LLBC_PrintLine("The doubleVal: %f", doubleVal);

    LLBC_PrintLine("Seek(End, -sizeof(double)), and read again the double value:");
    file.Seek(LLBC_FileSeekOrigin::End, -8);
    doubleVal = 0.0; file.Read(doubleVal);
    LLBC_PrintLine("The doubleVal: %f", doubleVal);

    LLBC_PrintLine("Now file size: %ld, file pos: %ld", file.GetFileSize(), file.GetFilePosition());
    file.Seek(LLBC_FileSeekOrigin::Current, -16);
    LLBC_PrintLine("After Seek(Current, -16), file size: %ld, file pos: %ld", file.GetFileSize(), file.GetFilePosition());

    // Test ReadLine/WriteLine/ReadToEnd methods:
    LLBC_PrintLine("ReOpen file for test ReadLine/WriteLine/ReadToEnd methods:");
    file.ReOpen(LLBC_FileMode::BinaryReadWrite);

    LLBC_PrintLine("WriteLine(\"Hello World!\"):");
    file.WriteLine("Hello World!");
    LLBC_PrintLine("WriteLine(\"Hey, Judy!\"):");
    file.WriteLine("Hey, Judy!");

    file.SetFilePosition(0);
    LLBC_PrintLine("Read lines:");
    LLBC_PrintLine("First line: %s", file.ReadLine().c_str());
    LLBC_PrintLine("Second line: %s", file.ReadLine().c_str());
    const LLBC_String notExistLine = file.ReadLine();
    LLBC_PrintLine("Not exist line: %s, error: %s", notExistLine.c_str(), LLBC_FormatLastError());

    LLBC_PrintLine("");

    return true;
}
コード例 #23
0
int TestCase_Core_Utils_Text::Run(int argc, char *argv[])
{
    LLBC_PrintLine("core/utils/Util_Text test:");

    // Split string test.
    LLBC_String str = "hello world hello world";
    LLBC_PrintLine("split string: %s", str.c_str());
    std::vector<LLBC_String> strs;
    LLBC_SplitString(str, " ", strs);
    LLBC_PrintLine("result(sub string count: %lu):", strs.size());
    for(size_t i = 0; i < strs.size(); i ++)
    {
        LLBC_PrintLine("\t%s", strs[i].c_str());
    }
    LLBC_PrintLine("");

    // Filter-out test.
    LLBC_PrintLine("filter out string: %s", str.c_str());
    LLBC_PrintLine("result: %s", LLBC_FilterOutString(str, " ").c_str());
    LLBC_PrintLine("");

    // Upper<->Lower test.
    str = "AaBbCcDd eEfFgG";
    LLBC_PrintLine("string [%s] to Upper: %s", str.c_str(), LLBC_ToUpper( str.c_str()).c_str());
    LLBC_PrintLine("string [%s] to Lower: %s", str.c_str(), LLBC_ToLower( str.c_str()).c_str());
    LLBC_PrintLine("");

    // Trim test(include left, right).
    str = "     Hello World     \t\t\t";
    LLBC_PrintLine("trim test, string: %s", str.c_str());
    LLBC_PrintLine("after trim left(len: %lu): %s", 
        LLBC_TrimLeft(str).length(), LLBC_TrimLeft(str).c_str());
    LLBC_PrintLine("after trim right(len: %lu): %s",
        LLBC_TrimRight(str).length(), LLBC_TrimRight(str).c_str());
    LLBC_PrintLine("after trim(left and right)(len: %lu): %s",
        LLBC_Trim(str).length(), LLBC_Trim(str).c_str());
    LLBC_PrintLine("");

    // String -> Number test.
    str = "-30";
    LLBC_PrintLine("string [%s] to number(Str2Int32): %d", 
        str.c_str(), LLBC_Str2Int32( str.c_str()));
    LLBC_PrintLine("string [%s] to number(Str2Long): %ld", 
        str.c_str(), LLBC_Str2Long( str.c_str()));
    LLBC_PrintLine("string [%s] to number(Str2Int64): %lld", 
        str.c_str(), LLBC_Str2Int64( str.c_str()));
    LLBC_PrintLine("string [%s] to number(Str2UInt32): %u", 
        str.c_str(), LLBC_Str2UInt32( str.c_str()));
    LLBC_PrintLine("string [%s] to number(Str2ULong): %lu", 
        str.c_str(), LLBC_Str2ULong( str.c_str()));
    LLBC_PrintLine("string [%s] to pointer(Str2Ptr): %p",
        "30", LLBC_Str2Ptr("30"));
    LLBC_PrintLine("string [%s] to pointer(Str2Ptr): %p",
        "0xcdcdcdcd", LLBC_Str2Ptr("0xcdcdcdcd"));
    LLBC_PrintLine("string [%s] to number(Str2UInt64): %llu", 
        str.c_str(), LLBC_Str2UInt64( str.c_str()));
    LLBC_PrintLine("string [%s] to number(Str2Double): %f", 
        str.c_str(), LLBC_Str2Double( str.c_str()));
    LLBC_PrintLine("");

    // Number -> String test.
    {
        sint8 sint8Val = 'a';
        LLBC_PrintLine("LLBC_Num2Str<sint8>()[%c] -> string(base:10): %s",
            sint8Val, LLBC_Num2Str(sint8Val).c_str());
        uint8 uint8Val = 97;
        LLBC_PrintLine("LLBC_Num2Str<uint8>()[%d] -> string(base:10): %s",
            uint8Val, LLBC_Num2Str(uint8Val).c_str());

        sint16 sint16Val = -16;
        LLBC_PrintLine("LLBC_Num2Str<sint16>()[%d] -> string(base:16): %s",
            sint16Val, LLBC_Num2Str(sint16Val, 16).c_str());
        uint16 uint16Val = 16;
        LLBC_PrintLine("LLBC_Num2Str<uint16>()[%u] -> string(base:8): %s",
            uint16Val, LLBC_Num2Str(uint16Val, 8).c_str());

        sint32 sint32Val = -32;
        LLBC_PrintLine("LLBC_Num2Str<sint32>()[%d] -> string(base:10): %s",
            sint32Val, LLBC_Num2Str(sint32Val).c_str());
        uint32 uint32Val = 32;
        LLBC_PrintLine("LLBC_Num2Str<uint32>()[%u] -> string(base:10): %s",
            uint32Val, LLBC_Num2Str(uint32Val).c_str());

        long longVal = -1;
        LLBC_PrintLine("LLBC_Num2Str<long>()[%ld] -> string(base:10): %s",
            longVal, LLBC_Num2Str(longVal).c_str());
        llbc::ulong ulongVal = -1;
        LLBC_PrintLine("LLBC_Num2Str<ulong>()[%lu] -> string(base:10): %s",
            ulongVal, LLBC_Num2Str(ulongVal).c_str());

        sint64 sint64Val = -64;
        LLBC_PrintLine("LLBC_Num2Str<sint64>()[%lld] -> string(base:10): %s",
            sint64Val, LLBC_Num2Str(sint64Val).c_str());
        uint64 uint64Val = 64;
        LLBC_PrintLine("LLBC_Num2Str<uint64>()[%llu] -> string(base:10): %s",
            uint64Val, LLBC_Num2Str(uint64Val).c_str());

        float fVal = 1.0f;
        LLBC_PrintLine("LLBC_Num2Str<float>()[%f] -> string: %s",
            fVal, LLBC_Num2Str(fVal).c_str());
        double doubleVal = -1.0f;
        LLBC_PrintLine("LLBC_Num2Str<double>()[%f] -> string: %s",
            doubleVal, LLBC_Num2Str(doubleVal).c_str());

        int *intPtr = reinterpret_cast<int *>(0xcdcdcdcd);
        LLBC_PrintLine("LLBC_Num2Str<int *>()[%p] -> string: %s",
            intPtr, LLBC_Num2Str(intPtr).c_str());
        const void *voidPtr = reinterpret_cast<const void *>(0xfffffffe);
        LLBC_PrintLine("LLBC_Num2Str<void *>()[%p] -> string: %s",
            voidPtr, LLBC_Num2Str(voidPtr).c_str());
    }

    LLBC_PrintLine("");

    // DirName, BaseName, ExtensionName test.
#if LLBC_TARGET_PLATFORM_NON_WIN32
    LLBC_String path = "/usr/tmp/a.txt";
#else
    LLBC_String path = "c:\\Windows\\a.txt";
#endif
    LLBC_PrintLine("path: %s", path.c_str());
    LLBC_PrintLine("\tdirname: %s", LLBC_DirName(path).c_str());
    LLBC_PrintLine("\tbasename(include extension): %s", LLBC_BaseName(path).c_str());
    LLBC_PrintLine("\tbasename(not-include extension): %s", LLBC_BaseName(path, false).c_str());
    LLBC_PrintLine("\textension: %s", LLBC_ExtensionName(path).c_str());

    LLBC_PrintLine("Press any key to continue ...");
    getchar();

    return 0;
}
コード例 #24
0
ファイル: TestCase_Comm_Svc.cpp プロジェクト: lailongwei/llbc
int TestCase_Comm_Svc::Run(int argc, char *argv[])
{
    LLBC_PrintLine("Server/Client test:");
    if (argc < 5)
    {
        LLBC_PrintLine("argument error, eg: ./a [client/server] [normal/raw] ip port");
        return -1;
    }

    // Parse arguments.
    const char *ip = argv[3];
    const int port = LLBC_Str2Int32(argv[4]);
    const bool asClient = LLBC_String(argv[1]) == "client" ? true : false;
    LLBC_IService::Type svcType = 
        LLBC_String(argv[2]) == "normal" ? LLBC_IService::Normal : LLBC_IService::Raw;

    LLBC_PrintLine("Will start %s type service, service type: %s",
        asClient ? "CLIENT" : "SERVER",
        svcType == LLBC_IService::Normal ? "Normal" : "Raw");

    // Create service
    LLBC_IService *svc = LLBC_IService::Create(svcType);
    TestFacade *facade = LLBC_New(TestFacade);
    svc->RegisterFacade(facade);
    svc->Subscribe(OPCODE, facade, &TestFacade::OnDataArrival);
    svc->SuppressCoderNotFoundWarning();
    svc->Start(2);

    // Connect to server / Create listen session to wait client connect.
    int sessionId;
    if (!asClient)
    {
        LLBC_PrintLine("Will listening in %s:%d", ip, port);
        if ((sessionId = svc->Listen(ip, port)) == 0)
        {
            LLBC_PrintLine("Create session failed, reason: %s", LLBC_FormatLastError());
            LLBC_Delete(svc);

            return -1;
        }
    }
    else
    {
        // Client service, we create some clients to test service.
        int clientCount;
        const int pollerType = LLBC_PollerType::Str2Type(LLBC_CFG_COMM_POLLER_MODEL);
        if (pollerType == LLBC_PollerType::SelectPoller)
            clientCount = 50;
        else
            clientCount = 1024;

        LLBC_PrintLine("Create %d clients to test", clientCount);

        for (int i = 0; i < clientCount; i++)
        {
            const int sessionId = svc->Connect(ip, port);

            const int dataSize = 4096;
            char *data = LLBC_Malloc(char, dataSize);
            ::memset(data, 1, dataSize);

            LLBC_Packet *packet = LLBC_New(LLBC_Packet);
            packet->SetHeader(sessionId, OPCODE, 0);
            packet->Write(data, dataSize);

            LLBC_Free(data);

            svc->Send(packet);

            // Test unhandled packet(unsubscribe opcode).
            LLBC_Packet *unhandledPacket = LLBC_New(LLBC_Packet);
            unhandledPacket->SetHeader(sessionId, OPCODE + 10000, 0);
            unhandledPacket->Write("Hello World", 12);

            svc->Send(unhandledPacket);
        }
    }

    LLBC_PrintLine("Press any key to continue...");
    getchar();

    return 0;
}
コード例 #25
0
void TestCase_Com_DataType::StringBaseTest()
{
    LLBC_PrintLine("String base functions test:");

    LLBC_String testStr;
    testStr.format("%s", "hello world!");
    testStr.append_format("%s", "hello world!");
    LLBC_PrintLine("LLBC_String::format/append_format test: %s", testStr.c_str());

    LLBC_String testStr2;
    for(int i = 0; i < 1000; i++)
    {
        testStr.append("hello world!");
    }

    testStr2.append_format("%s", testStr.c_str());
    LLBC_PrintLine("LLBC_String:format large string test: %s", testStr2.c_str());

    // tolower/toupper test.
    testStr = "Hello WoRlD!";
    LLBC_PrintLine("'%s' to lower: '%s'", testStr.c_str(), testStr.tolower().c_str());
    LLBC_PrintLine("'%s' to upper: '%s'", testStr.c_str(), testStr.toupper().c_str());

    // isalpha/isupper/islower.
    LLBC_String str("HELLO");
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "hello";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "HeLlO";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "hello123";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "HELLO123";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "Hello123";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "H";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "h";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());
    str = "3";
    LLBC_PrintLine("%s islower?%d, isupper?%d, isalpha?%d", 
        str.c_str(), str.islower(), str.isupper(), str.isalpha());

    LLBC_PrintLine("\n");
}
コード例 #26
0
ファイル: TestCase_Core_Log.cpp プロジェクト: lailongwei/llbc
int TestCase_Core_Log::Run(int argc, char *argv[])
{
    LLBC_PrintLine("core/log test:");

#if LLBC_TARGET_PLATFORM_IPHONE
    const LLBC_Bundle *mainBundle = LLBC_Bundle::GetMainBundle();
    if(LLBC_LoggerManagerSingleton->Initialize(mainBundle->GetBundlePath() + "/" + "Logger_Cfg.cfg") != LLBC_OK)
#else

    if(LLBC_LoggerManagerSingleton->Initialize("Logger_Cfg.cfg") != LLBC_OK)
#endif
    {
        LLBC_FilePrintLine(stderr, "Initialize logger manager failed, err: %s", LLBC_FormatLastError());
        LLBC_FilePrintLine(stderr, "Forgot copy Logger_Cfg.cfg test config file to CWD?");
        return -1;
    }

    // Use root logger to test.
    LLBC_DEBUG_LOG("This is a debug log message.");
    LLBC_DEBUG_LOG2("test_tag", "This is a debug log message.");

#if LLBC_CFG_LOG_USING_WITH_STREAM
    LLBC_DEBUG_LOG("Message type test, char: " <<'a' <<", bool: " <<true <<", uint8: " <<(uint8)8
        <<", sint16: " <<(sint16)-16 << ", uint16: " <<(uint16)16 <<", sint32: " <<-32
        <<", uint32: " <<(uint32)32 <<", long: " <<(long)-1 <<", ulong: " <<(llbc::ulong)1
        <<", sint64: " <<(sint64)-64 <<", uint64: " <<(uint64)64 <<", float: " <<(float)1.0
        <<", double: " <<2.0 <<", ldouble: " <<(ldouble)3.0);

    std::string stdStr = "This is a std::string";
    LLBC_String llbcStr = "This is a LLBC_String";
    LLBC_DEBUG_LOG("std::string operator << test: " <<stdStr <<", LLBC_String operator << test: " <<llbcStr);

    LLBC_Time now;
    LLBC_TimeSpan span(-30);
    LLBC_DEBUG_LOG("Current time: " <<now <<", TimeSpan: " <<span);

    // Test precision.
    double f = 3.14159;
    LLBC_DEBUG_LOG(std::setprecision(5) <<f);
    LLBC_DEBUG_LOG(std::setprecision(9) <<f);
    LLBC_DEBUG_LOG(std::setprecision(5) <<std::fixed <<f);
    LLBC_DEBUG_LOG(std::setprecision(9) <<std::fixed <<f);
#endif // LLBC_CFG_LOG_USING_WITH_STREAM`

    LLBC_INFO_LOG("This is a info log message.");
    LLBC_INFO_LOG2("test_tag", "This is a info log message.");

    LLBC_WARN_LOG("This is a warn log message.");
    LLBC_WARN_LOG2("test_tag", "This is a warn log message.");

    LLBC_ERROR_LOG("This is a error log message.");
    LLBC_ERROR_LOG2("test_tag", "This is a error log message.");

    LLBC_FATAL_LOG("This is a fatal log message.");
    LLBC_FATAL_LOG2("test_tag", "This is a fatal log message.");

    // Use test logger to test.
    LLBC_DEBUG_LOG_SPEC("test", "This is a debug log message.");
    LLBC_DEBUG_LOG_SPEC2("test", "test_tag", "This is a debug log message.");

    LLBC_INFO_LOG_SPEC("test", "This is a info log message.");
    LLBC_INFO_LOG_SPEC2("test", "test_tag", "This is a info log message.");

    LLBC_WARN_LOG_SPEC("test", "This is a warn log message.");
    LLBC_WARN_LOG_SPEC2("test", "test_tag", "This is a warn log message.");

    LLBC_ERROR_LOG_SPEC("test", "This is a error log message.");
    LLBC_ERROR_LOG_SPEC2("test", "test_tag", "This is a error log message.");

    LLBC_FATAL_LOG_SPEC("test", "This is a fatal log message.");
    LLBC_FATAL_LOG_SPEC2("test", "test_tag", "This is a fatal log message.");

    // Log file delete test.
    for (int i = 0; i < 20; i++)
    {
        LLBC_DEBUG_LOG_SPEC("deltest", "This is a deltest logger message.");
        LLBC_ThreadManager::Sleep(1000);
    }

    // Peform performance test.
    LLBC_PrintLine("Perform preformance test:");
    LLBC_CPUTime begin = LLBC_CPUTime::Current();
    const int loopLmt = 500000;
    for (int i = 0; i < loopLmt; i++)
        LLBC_DEBUG_LOG_SPEC("perftest", "performance test msg");
    LLBC_LoggerManagerSingleton->Finalize();

    LLBC_CPUTime elapsed = LLBC_CPUTime::Current() - begin;
    LLBC_PrintLine("Performance test completed, "
        "log size:%d, elapsed time: %s", loopLmt, elapsed.ToString().c_str());

    LLBC_PrintLine("Press any key to continue ...");
    getchar();

    return 0;
}
コード例 #27
0
void TestCase_Comm_PacketHeaderParts::TestSetToPacket()
{
    LLBC_PrintLine("Test SetToPacket() method:");
    //! First, We must design packet header format.
    LLBC_PrintLine("  Fristly, we design packet header format.");
    LLBC_PacketHeaderDesc *headerDesc = LLBC_New(LLBC_PacketHeaderDesc);

    int serialNo = 0;
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(sint8)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(uint8)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(sint16)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(uint16)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(sint32))
        .SetIsLenPart(true).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(uint32))
        .SetIsOpcodePart(true).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(sint64)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(uint64)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(float)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(sizeof(double)).Done();
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(13).Done(); // "Hello World!"\0
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(19).Done(); // "Hello std::string!"\0
    headerDesc->AddPartDesc()
        .SetSerialNo(serialNo++).SetPartLen(19).Done(); // "Hello LLBC_String!"\0

    LLBC_PrintLine("  Design packet header done, header length: %lu", headerDesc->GetHeaderLen());

    // Set header format describe to llbc framework.
    LLBC_Print("  Set to llbc framework...");
    LLBC_IService::SetPacketHeaderDesc(headerDesc);
    LLBC_PrintLine("Done!");

    // Set header value to packet.
    LLBC_Print("Set the header parts to packet...");
    LLBC_Packet packet;
    _parts.SetToPacket(packet);
    LLBC_PrintLine("Done!");

    // Fetch from packet.
    LLBC_PrintLine("Fetch values from packet.");
    serialNo = 0;
    LLBC_PrintLine("  serial %d: %c", serialNo, packet.GetHeaderPartAsSInt8(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %d", serialNo, packet.GetHeaderPartAsUInt8(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %d", serialNo, packet.GetHeaderPartAsSInt16(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %u", serialNo, packet.GetHeaderPartAsUInt16(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %d", serialNo, packet.GetHeaderPartAsSInt32(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %u", serialNo, packet.GetHeaderPartAsUInt32(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %lld", serialNo, packet.GetHeaderPartAsSInt64(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %llu", serialNo, packet.GetHeaderPartAsUInt64(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %f", serialNo, packet.GetHeaderPartAsFloat(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %f", serialNo, packet.GetHeaderPartAsDouble(serialNo)), serialNo++;
    LLBC_PrintLine("  serial %d: %s", serialNo, packet.GetHeaderPartAsStr(serialNo).c_str()), serialNo++; // "Hello World!"
    LLBC_PrintLine("  serial %d: %s", serialNo, packet.GetHeaderPartAsStr(serialNo).c_str()), serialNo++; // "Hello std::string!"
    LLBC_PrintLine("  serial %d: %s", serialNo, packet.GetHeaderPartAsStr(serialNo).c_str()), serialNo++; // "Hello LLBC_String!"
    LLBC_PrintLine("  Fetch Done!");
}
コード例 #28
0
void TestCase_Comm_PacketHeaderParts::TestOne(int serialNo, const T &val, const char *typeDesc)
{
    LLBC_PrintLine("Set %s value, serial no: %d", typeDesc, serialNo);
    _parts.SetPart(serialNo, val);
    LLBC_PrintLine("  After set, has value? %s", _parts.IsHasPart(serialNo) ? "true" : "false");
}
コード例 #29
0
void TestCase_Com_DataType::RawTest()
{
    LLBC_PrintLine("Raw types test:");
    LLBC_PrintLine("sizeof(sint8): %lu", sizeof(sint8));
    LLBC_PrintLine("sizeof(sint16): %lu", sizeof(sint16));
    LLBC_PrintLine("sizeof(sint32): %lu", sizeof(sint32));
    LLBC_PrintLine("sizeof(sint64): %lu", sizeof(sint64));
    LLBC_PrintLine("");

    LLBC_PrintLine("sizeof(uint8): %lu", sizeof(uint8));
    LLBC_PrintLine("sizeof(uint16): %lu", sizeof(sint16));
    LLBC_PrintLine("sizeof(uint32): %lu", sizeof(sint32));
    LLBC_PrintLine("sizeof(uint64): %lu", sizeof(sint64));
    LLBC_PrintLine("");

    LLBC_PrintLine("sizeof(tchar): %lu", sizeof(tchar));

    LLBC_PrintLine("\n");
}
コード例 #30
0
int TestCase_Comm_PacketOp::Run(int argc, char *argv[])
{
    LLBC_PrintLine("llbc library communication/packet test:");

    // Raw data type read/write test.
    std::cout <<"Raw data type read/write test(net byte order flag: " 
        <<(LLBC_CFG_COMM_ORDER_IS_NET_ORDER ? "TRUE" : "FALSE") <<"):" <<std::endl;
    bool boolVal = true;
    char charVal = 'X';
    sint8 sint8Val = -8;
    uint8 uint8Val = 8;
    sint16 sint16Val = -16;
    uint16 uint16Val = 16;
    sint32 sint32Val = -32;
    uint32 uint32Val = 32;
    sint64 sint64Val = -64;
    uint64 uint64Val = 64;
    long longVal = -1;
    LLBC_NS ulong ulongVal = 1;
    float floatVal = 1.01f;
    double doubleVal = 2.02;

    LLBC_Packet packet;
    packet <<boolVal <<charVal <<sint8Val <<uint8Val 
        <<sint16Val <<uint16Val <<sint32Val <<uint32Val
        <<sint64Val <<uint64Val <<longVal <<ulongVal
        <<floatVal <<doubleVal;
    packet >>boolVal >>charVal >>sint8Val >>uint8Val
        >>sint16Val >>uint16Val >>sint32Val >>uint32Val
        >>sint64Val >>uint64Val >>longVal >>ulongVal
        >>floatVal >>doubleVal;
    std::cout <<"Packet::Read(): boolVal: " <<boolVal <<", charVal: " <<charVal
        <<", sint8Val: " <<static_cast<sint32>(sint8Val) <<", uint8Val: " <<static_cast<uint32>(uint8Val)
        <<", sint16Val: " <<sint16Val <<", uint16Val: " <<uint16Val
        <<", sint32Val: " <<sint32Val <<", uint32Val: " <<uint32Val
        <<", sint64Val: " <<sint64Val <<", uint64Val: " <<uint64Val
        <<", longVal: " <<longVal <<", ulongVal: " <<ulongVal
        <<", floatVal: " <<floatVal <<", doubleVal: " <<doubleVal
        <<std::endl;

    // std::string/LLBC_String test.
    std::cout <<"std::string/LLBC_String read/write test:" <<std::endl;
    std::string stdStr = "Hello, This is a std::string object";
    LLBC_String llbcStr = "Hello, This is a LLBC_String object";

    packet <<stdStr <<llbcStr >>stdStr >>llbcStr;
    std::cout <<"Packet::Read(): std::string: " <<stdStr <<std::endl;
    std::cout <<"Packet::Read(): LLBC_String: " <<llbcStr <<std::endl;

    // STL containers test.
    std::cout <<"STL container test: " <<std::endl;
    std::vector<std::list<LLBC_String> > stlCont;
    stlCont.push_back( std::list<LLBC_String>() );
    stlCont.push_back( std::list<LLBC_String>() );
    stlCont[0].push_back("World");
    stlCont[0].push_front("Primer");
    stlCont[1].push_back("Foot");
    stlCont[1].push_front("Service Entry");
    packet <<stlCont;
    stlCont.clear();
    packet >>stlCont;
    std::cout <<"Packet::Read(): std::vector<std::list<LLBC_String> >, size = " <<stlCont.size() <<std::endl;
    for(size_t i = 0; i < stlCont.size(); i ++)
    {
        std::cout <<"  elem[ " <<i <<"] value: " <<std::endl;
        std::list<LLBC_String>::const_iterator it = stlCont[i].begin();
        for(int j = 0; it != stlCont[i].end(); it ++, j ++)
        {
            std::cout <<"    elem[" <<i <<"][" <<j <<"] value: " <<*it <<std::endl;
        }
    }

    // Base methods test.
    std::cout <<"\nBase methods test:" <<std::endl;
    LLBC_Packet packet2;
    packet2.SetOpcode(10086);
    packet2.SetStatus(-1);
    packet2.SetServiceId(110);
    packet2.SetFlags(1111);
    std::cout <<"After set opcode/status/serviceId/flags, these values are:" <<std::endl;
    std::cout <<"  opcode: " <<packet2.GetOpcode() <<std::endl;
    std::cout <<"  status: " <<packet2.GetStatus() <<std::endl;
    std::cout <<"  serviceId: " <<packet2.GetServiceId() <<std::endl;
    std::cout <<"  flags: " <<packet2.GetFlags() <<std::endl;
    std::cout <<"  packet length: " <<packet2.GetLength() <<std::endl;
    std::cout <<"  payload length: " <<packet2.GetPayloadLength() <<std::endl;

    std::cout <<"Test packet header part set methods:" <<std::endl;
    packet2.SetHeaderPartVal(1, 119);
    std::cout <<"After set, opcode: " <<packet2.GetHeaderPartAsSInt16(1) <<std::endl;

    std::cout <<"Press any key to continue ...";
    getchar();

    return 0;
}