📄 uuidtest.cpp
字号:
//
// UUIDTest.cpp
//
// $Id: //poco/Main/Foundation/testsuite/src/UUIDTest.cpp#5 $
//
// Copyright (c) 2004, Guenter Obiltschnig/Applied Informatics.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Redistributions in any form must be accompanied by information on
// how to obtain complete source code for this software and any
// accompanying software that uses this software. The source code
// must either be included in the distribution or be available for no
// more than the cost of distribution plus a nominal fee, and must be
// freely redistributable under reasonable conditions. For an
// executable file, complete source code means the source code for all
// modules it contains. It does not include source code for modules or
// files that typically accompany the major components of the operating
// system on which the executable file runs.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "UUIDTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Foundation/UUID.h"
using Foundation::UUID;
UUIDTest::UUIDTest(const std::string& name): CppUnit::TestCase(name)
{
}
UUIDTest::~UUIDTest()
{
}
void UUIDTest::testParse()
{
UUID uuid("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
assert (uuid.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
uuid.parse("6BA7B810-9DAD-11D1-80B4-00C04FD430C8");
assert (uuid.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
}
void UUIDTest::testBuffer()
{
UUID uuid("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
char buffer[16];
uuid.copyTo(buffer);
UUID uuid2;
uuid2.copyFrom(buffer);
assert (uuid2.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
}
void UUIDTest::testCompare()
{
UUID nil;
assert (nil.isNil());
assert (UUID::nil().isNil());
UUID uuid1 = nil;
UUID uuid2;
assert (uuid1.isNil());
assert (uuid1 == nil);
assert (!(uuid1 != nil));
assert (uuid1 >= nil);
assert (uuid1 <= nil);
assert (!(uuid1 > nil));
assert (!(uuid1 < nil));
assert (uuid1.toString() == "00000000-0000-0000-0000-000000000000");
uuid1 = UUID::dns();
assert (!uuid1.isNil());
assert (uuid1 != nil);
assert (!(uuid1 == nil));
assert (uuid1 >= nil);
assert (!(uuid1 <= nil));
assert (uuid1 > nil);
assert (!(uuid1 < nil));
assert (uuid1.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
assert (nil != uuid1);
assert (!(nil == uuid1));
assert (!(nil >= uuid1));
assert (nil <= uuid1);
assert (!(nil > uuid1));
assert (nil < uuid1);
uuid2 = uuid1;
assert (uuid2 == uuid1);
assert (!(uuid2 != uuid1));
assert (uuid2 >= uuid1);
assert (uuid2 <= uuid1);
assert (!(uuid2 > uuid1));
assert (!(uuid2 < uuid1));
}
void UUIDTest::testVersion()
{
UUID uuid("db4fa7e9-9e62-4597-99e0-b1ec0b59800e");
UUID::Version v = uuid.version();
assert (v == UUID::UUID_RANDOM);
uuid.parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
v = uuid.version();
assert (v == UUID::UUID_TIME_BASED);
uuid.parse("d2ee4220-3625-11d9-9669-0800200c9a66");
v = uuid.version();
assert (v == UUID::UUID_TIME_BASED);
uuid.parse("360d3652-4411-4786-bbe6-b9675b548559");
v = uuid.version();
assert (v == UUID::UUID_RANDOM);
}
void UUIDTest::testVariant()
{
UUID uuid("db4fa7e9-9e62-4597-99e0-b1ec0b59800e");
int v = uuid.variant();
assert (v == 2);
uuid.parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
v = uuid.variant();
assert (v == 2);
uuid.parse("d2ee4220-3625-11d9-9669-0800200c9a66");
v = uuid.variant();
assert (v == 2);
uuid.parse("360d3652-4411-4786-bbe6-b9675b548559");
v = uuid.variant();
assert (v == 2);
}
void UUIDTest::setUp()
{
}
void UUIDTest::tearDown()
{
}
CppUnit::Test* UUIDTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UUIDTest");
CppUnit_addTest(pSuite, UUIDTest, testParse);
CppUnit_addTest(pSuite, UUIDTest, testBuffer);
CppUnit_addTest(pSuite, UUIDTest, testCompare);
CppUnit_addTest(pSuite, UUIDTest, testVersion);
CppUnit_addTest(pSuite, UUIDTest, testVariant);
return pSuite;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -