Exemplo n.º 1
0
    bool IsWellFormed::test() {
        string s1 = "[()[]{()()}]";
        string s2 = "[()[]{()()";
        string s3 = ")[]";
        string s4 = "[](";

        if (!isWellFormed(s1)) {
            cout << "Should be true: " << s1 << endl;
            return false;
        }

        if (isWellFormed(s2)) {
            cout << "Should be false: " << s2 << endl;
            return false;
        }

        if (isWellFormed(s3)) {
            cout << "Should be false: " << s3 << endl;
            return false;
        }

        if (isWellFormed(s4)) {
            cout << "Should be false: " << s4 << endl;
            return false;
        }

        return true;
    }
Exemplo n.º 2
0
void UniqueFd::reset(Fd fd) {
    auto& sys = sSyscalls.get();
    std::swap(fd, mFd);
    if (isWellFormed(fd)) {
        expectOk(sys.close(fd));
    }
}
void BidirectionalLinkListUtil::insertLinkBeforeTarget(
                                                   BidirectionalLink  *newNode,
                                                   BidirectionalLink  *target)
{
    BSLS_ASSERT(newNode);
#ifdef BDE_BUILD_TARGET_SAFE_2
    BSLS_ASSERT_SAFE(isWellFormed(target, target));
#endif

    // Prepending before an empty list is *explicitly* *allowed*

    if (!target) {
        newNode->reset();
    }
    else if (BidirectionalLink *prev = target->previousLink()) {
        newNode->setPreviousLink(prev);
        prev->setNextLink(newNode);
        newNode->setNextLink(target);
        target->setPreviousLink(newNode);
    }
    else {
        newNode->setPreviousLink(0);  // asserted precondition
        newNode->setNextLink(target);
        target->setPreviousLink(newNode);
    }
}
Exemplo n.º 4
0
void Normalizer2DataBuilder::setRoundTripMapping(UChar32 c, const UnicodeString &m) {
    if(U_IS_SURROGATE(c)) {
        fprintf(stderr,
                "error in gennorm2 phase %d: "
                "illegal round-trip mapping from surrogate code point U+%04lX\n",
                (int)phase, (long)c);
        exit(U_INVALID_FORMAT_ERROR);
    }
    if(!isWellFormed(m)) {
        fprintf(stderr,
                "error in gennorm2 phase %d: "
                "illegal round-trip mapping from U+%04lX to malformed string\n",
                (int)phase, (long)c);
        exit(U_INVALID_FORMAT_ERROR);
    }
    int32_t numCP=u_countChar32(m.getBuffer(), m.length());
    if(numCP!=2) {
        fprintf(stderr,
                "error in gennorm2 phase %d: "
                "illegal round-trip mapping from U+%04lX to %d!=2 code points\n",
                (int)phase, (long)c, (int)numCP);
        exit(U_INVALID_FORMAT_ERROR);
    }
    Norm *p=checkNormForMapping(createNorm(c), c);
    p->mapping=new UnicodeString(m);
    p->mappingType=Norm::ROUND_TRIP;
    p->mappingCP=U_SENTINEL;
}
Exemplo n.º 5
0
//--------------------------------------------------------------------------
void BoundingBoxTests::testCreator()
{
  CPPUNIT_ASSERT_EQUAL(6_z * sizeof (float), sizeof (AABB3f));
  CPPUNIT_ASSERT_EQUAL(6_z * sizeof (int32_t), sizeof (AABB3i));
  CPPUNIT_ASSERT_EQUAL(6_z * sizeof (double), sizeof (AABB3g));

  // Display
  std::cout << "Displaying AABBs" << std::endl << a1 << a2 << a3
            << a4 << a5 << a6 << a7 << std::endl; // << i1 << i2 << i3

  // Check lower corner of the box is <= to the upper corner
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(a1));
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(a2));
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(a3));
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(a4));
  checkBoxDummy(a8);
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(a5));
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(a6));
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(a7));

  // Integer boxes
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(i1));
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(i2));
  CPPUNIT_ASSERT_EQUAL(true, isWellFormed(i3));
  checkBox(i2, Vector2i(-2, -2), Vector2i(2, 2));
  checkBox(i3, Vector2i(42, 42), Vector2i(42, 42));

  // Change dimension
  a5.set({1,1,1}, {2,2,2});
  CPPUNIT_ASSERT_EQUAL(true, eq(a5, a2));
  CPPUNIT_ASSERT_EQUAL(true, eq(a7, a2));

  // Getter
  CPPUNIT_ASSERT_EQUAL(true, vector::eq(a5.m_bbmin, a5.get(aabb::LowerCorner)));
  CPPUNIT_ASSERT_EQUAL(true, vector::eq(a5.m_bbmax, a5.get(aabb::UpperCorner)));
  CPPUNIT_ASSERT_EQUAL(true, vector::ne(a4.m_bbmin, a5.get(aabb::LowerCorner)));
  CPPUNIT_ASSERT_EQUAL(true, vector::ne(a4.m_bbmax, a5.get(aabb::UpperCorner)));

  // Try to malformed a AABB. Check security is triggered
  CPPUNIT_ASSERT_THROW(a5.set(Vector3f(2,2,2), Vector3f(1,1,1)), std::out_of_range);
  CPPUNIT_ASSERT_THROW(AABB3f({2,2,2}, {1,1,1}), std::out_of_range);
  CPPUNIT_ASSERT_THROW(AABB3f(Vector3f(2), Vector3f(1)), std::out_of_range);
}
Exemplo n.º 6
0
FastRational::FastRational( const char * s, const int base )
{
  mpq_init(mpq);
  mpq_set_str(mpq, s, base);
  mpq_canonicalize( mpq );
  has_mpq = true;
  make_word( );
  if ( has_word )
    kill_mpq( );

  assert( isWellFormed( ) );
}
Exemplo n.º 7
0
void Normalizer2DataBuilder::setOneWayMapping(UChar32 c, const UnicodeString &m) {
    if(!isWellFormed(m)) {
        fprintf(stderr,
                "error in gennorm2 phase %d: "
                "illegal one-way mapping from U+%04lX to malformed string\n",
                (int)phase, (long)c);
        exit(U_INVALID_FORMAT_ERROR);
    }
    Norm *p=checkNormForMapping(createNorm(c), c);
    p->mapping=new UnicodeString(m);
    p->mappingType=Norm::ONE_WAY;
    p->setMappingCP();
}
void BidirectionalLinkListUtil::spliceListBeforeTarget
                                                   (BidirectionalLink *first,
                                                    BidirectionalLink *last,
                                                    BidirectionalLink *target)
{
    BSLS_ASSERT_SAFE(first);
    BSLS_ASSERT_SAFE(last);
#ifdef BDE_BUILD_TARGET_SAFE_2
    // Test to avoid creating loops is O(N) expensive, so check only in SAFE_2

    BidirectionalLink *cursor = first;
    while(cursor != last->nextLink()) {
        BSLS_ASSERT_SAFE(cursor != target);
        cursor = cursor->nextLink();
    }
    BSLS_ASSERT_SAFE(isWellFormed(first, last));
#endif

    // unlink from existing list

    if (BidirectionalLink* prev = first->previousLink()) {
        prev->setNextLink(last->nextLink());
    }
    if (BidirectionalLink* next = last->nextLink()) {
        next->setPreviousLink(first->previousLink());
    }

    // update into spliced location:

    if (!target) {
        // Prepending target an empty list is *explicitly* *allowed*
        // The "spliced" segment is still extracted from the original list

        first->setPreviousLink(0);  // redundant with pre-condition
        last->setNextLink(0);
    }
    else {
        if (BidirectionalLink *prev = target->previousLink()) {
            first->setPreviousLink(prev);
            prev->setNextLink(first);
        }
        else {
            first->setPreviousLink(0);
        }

        last->setNextLink(target);
        target->setPreviousLink(last);
    }
}
void BidirectionalLinkListUtil::insertLinkAfterTarget(
                                                    BidirectionalLink *newNode,
                                                    BidirectionalLink *target)
{
    BSLS_ASSERT_SAFE(newNode);
    BSLS_ASSERT_SAFE(target);

    BidirectionalLink *next = target->nextLink();

#ifdef BDE_BUILD_TARGET_SAFE_2
    BSLS_ASSERT_SAFE(!next || isWellFormed(target, next));
#endif

    target->setNextLink(newNode);
    if (next) {
        next->setPreviousLink(newNode);
    }

    newNode->setPreviousLink(target);
    newNode->setNextLink(next);
}
void BidirectionalLinkListUtil::unlink(BidirectionalLink *node)
{
    BSLS_ASSERT_SAFE(node);

    BidirectionalLink *prev = node->previousLink(), *next = node->nextLink();

    if (prev) {
        if (next) {
            BSLS_ASSERT_SAFE(isWellFormed(prev, next));

            next->setPreviousLink(prev);
            prev->setNextLink(next);
        }
        else {
            prev->setNextLink(0);
        }
    }
    else if (next) {
        next->setPreviousLink(0);
    }
}