Ejemplo n.º 1
0
void UUIDTest::testNameUUIDFromBytes() {
    char name[16] = {
        (char) 0x6b, (char) 0xa7, (char) 0xb8, (char) 0x11,
        (char) 0x9d, (char) 0xad, (char) 0x11, (char) 0xd1,
        (char) 0x80, (char) 0xb4, (char) 0x00, (char) 0xc0,
        (char) 0x4f, (char) 0xd4, (char) 0x30, (char) 0xc8 };

    UUID uuid = UUID::nameUUIDFromBytes(&name[0], 16);

    CPPUNIT_ASSERT_EQUAL(2, uuid.variant());
    CPPUNIT_ASSERT_EQUAL(3, uuid.version());

    CPPUNIT_ASSERT_EQUAL(0xaff565bc2f771745ULL, (unsigned long long) uuid.getLeastSignificantBits());
    CPPUNIT_ASSERT_EQUAL(0x14cdb9b4de013faaLL, uuid.getMostSignificantBits());

    uuid = UUID::nameUUIDFromBytes(std::vector<char>());
    CPPUNIT_ASSERT_EQUAL(2, uuid.variant());
    CPPUNIT_ASSERT_EQUAL(3, uuid.version());

    CPPUNIT_ASSERT_EQUAL(0xa9800998ecf8427eULL, (unsigned long long) uuid.getLeastSignificantBits());
    CPPUNIT_ASSERT_EQUAL(0xd41d8cd98f003204ULL, (unsigned long long) uuid.getMostSignificantBits());

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an NullPointerException exception",
        UUID::nameUUIDFromBytes(NULL, 1),
        NullPointerException);
}
Ejemplo n.º 2
0
bool UUID::equals( const UUID& value ) const {
    return this->getMostSignificantBits() == value.getMostSignificantBits() &&
           this->getLeastSignificantBits() == value.getLeastSignificantBits();
}
Ejemplo n.º 3
0
void UUIDTest::testFromStringStringException() {

    UUID uuid = UUID::fromString("0-0-0-0-0");

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("0-0-0-0-"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("00000"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("----"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("-0-0-0-0-0"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("-0-0-0-0"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("-0-0-0-"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("0--0-0-0"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("0-0-0-0-"),
        IllegalArgumentException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("-1-0-0-0-0"),
        IllegalArgumentException);

    uuid = UUID::fromString("123456789-0-0-0-0");
    CPPUNIT_ASSERT_EQUAL(0x2345678900000000LL, uuid.getMostSignificantBits());
    CPPUNIT_ASSERT_EQUAL(0x0LL, uuid.getLeastSignificantBits());

    uuid = UUID::fromString("111123456789-0-0-0-0");
    CPPUNIT_ASSERT_EQUAL(0x2345678900000000LL, uuid.getMostSignificantBits());
    CPPUNIT_ASSERT_EQUAL(0x0LL, uuid.getLeastSignificantBits());

    uuid = UUID::fromString("7fffffffffffffff-0-0-0-0");
    CPPUNIT_ASSERT_EQUAL(0xffffffff00000000ULL, (unsigned long long) uuid.getMostSignificantBits());
    CPPUNIT_ASSERT_EQUAL(0x0LL, uuid.getLeastSignificantBits());

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("8000000000000000-0-0-0-0"),
        NumberFormatException);

    uuid = UUID::fromString("7fffffffffffffff-7fffffffffffffff-7fffffffffffffff-0-0");
    CPPUNIT_ASSERT_EQUAL(0xffffffffffffffffULL, (unsigned long long) uuid.getMostSignificantBits());
    CPPUNIT_ASSERT_EQUAL(0x0LL, uuid.getLeastSignificantBits());

    uuid = UUID::fromString("0-0-0-7fffffffffffffff-7fffffffffffffff");
    CPPUNIT_ASSERT_EQUAL(0x0LL, uuid.getMostSignificantBits());
    CPPUNIT_ASSERT_EQUAL(0xffffffffffffffffULL, (unsigned long long) uuid.getLeastSignificantBits());

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("0-0-0-8000000000000000-0"),
        NumberFormatException);

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw an IllegalArgumentException exception",
        UUID::fromString("0-0-0-0-8000000000000000"),
        NumberFormatException);
}