Beispiel #1
0
    void run() {
        NamespaceString nss("unittests.rollback_truncate_collection");
        const ServiceContext::UniqueOperationContext opCtxPtr = cc().makeOperationContext();
        OperationContext& opCtx = *opCtxPtr;
        dropDatabase(&opCtx, nss);

        Lock::DBLock dbXLock(&opCtx, nss.db(), MODE_X);
        OldClientContext ctx(&opCtx, nss.ns());

        BSONObj doc = BSON("_id"
                           << "foo");

        ASSERT(!collectionExists(&ctx, nss.ns()));
        {
            WriteUnitOfWork uow(&opCtx);

            ASSERT_OK(userCreateNS(&opCtx,
                                   ctx.db(),
                                   nss.ns(),
                                   BSONObj(),
                                   CollectionOptions::parseForCommand,
                                   defaultIndexes));
            ASSERT(collectionExists(&ctx, nss.ns()));
            insertRecord(&opCtx, nss, doc);
            assertOnlyRecord(&opCtx, nss, doc);
            uow.commit();
        }
        assertOnlyRecord(&opCtx, nss, doc);

        // END OF SETUP / START OF TEST

        {
            WriteUnitOfWork uow(&opCtx);

            ASSERT_OK(truncateCollection(&opCtx, nss));
            ASSERT(collectionExists(&ctx, nss.ns()));
            assertEmpty(&opCtx, nss);

            if (!rollback) {
                uow.commit();
            }
        }
        ASSERT(collectionExists(&ctx, nss.ns()));
        if (rollback) {
            assertOnlyRecord(&opCtx, nss, doc);
        } else {
            assertEmpty(&opCtx, nss);
        }
    }
Beispiel #2
0
void processSymlinks(FILE *inf, CptObj *destArr, uint16 *baseLists) {
	char line[1024];
	dofgets(line, 1024, inf);
	assert(lineMatchSection(line, "SYMLINKS"));
	do {
		dofgets(line, 1024, inf);
		if (!isEndOfSection(line)) {
			char cptName[50];
			uint16 fromId = getInfo(line, "SYMLINK", cptName);
			CptObj *from = destArr + fromId;
			assertEmpty(from);
			dlinkNames[dlinkCount] = (char *)malloc(strlen(cptName) + 1);
			strcpy(dlinkNames[dlinkCount], cptName);

			dofgets(line, 1024, inf);
			assert((line[0] == '\t') && (line[1] == '\t') && (line[2] == '-') && (line[3] == '>'));
			char *stopCh;
			uint16 destId = (uint16)strtoul(line + 4, &stopCh, 16);
			assert(stopCh == (line + 8));
			assert((stopCh[0] == ':') && (stopCh[1] == ':'));

			dlinks[dlinkCount * 2 + 0] = fromId;
			dlinks[dlinkCount * 2 + 1] = destId;

			dlinkCount++;

			dofgets(line, 1024, inf);
			assert(isEndOfObject(line, "SYMLINK", fromId));
		} else
			break;
	} while (1);
}
Beispiel #3
0
void processCpts(FILE *inf, CptObj *destArr) {
	char line[1024];
	dofgets(line, 1024, inf);
	assert(lineMatchSection(line, "COMPACTS"));
	uint16 *resBuf = (uint16 *)malloc(MAX_OBJ_SIZE);
	do {
		dofgets(line, 1024, inf);
		if (!isEndOfSection(line)) {
			char cptName[50];
			uint16 id = getInfo(line, "COMPACT", cptName);
			CptObj *dest = destArr + id;
			assertEmpty(dest);
			dest->dbgName = (char *)malloc(strlen(cptName) + 1);
			dest->type = COMPACT;
			strcpy(dest->dbgName, cptName);
			memset(resBuf, 0, MAX_OBJ_SIZE);
			uint32 resPos = 0;

			do {
				dofgets(line, 1024, inf);
				if (!isEndOfObject(line, "COMPACT", id)) {
					assert((line[0] == '\t') && (line[1] == '\t'));
					char *stopCh;
					uint16 destId = (uint16)strtoul(line + 2, &stopCh, 16);
					assert(stopCh != (line + 2));
					assert((stopCh[0] == '-') && (stopCh[1] == '>'));
					if (resPos == 23) { // grafixProg
						assert(destId == 0);
						resBuf[resPos] = resBuf[resPos + 1] = 0;
						resPos += 2;
					} else if (resPos == 48) {	// turnProg. shouldn't it be 49?
						assert(destId == 0);
						resBuf[resPos] = resBuf[resPos + 1] = 0;
						resPos += 2;
					} else {
						resBuf[resPos] = destId;
						resPos++;
					}
				} else
					break;
			} while (1);
			assert(resPos < (MAX_OBJ_SIZE / 2));
			dest->len = resPos;
			dest->data = (uint16 *)malloc(resPos * 2);
			memcpy(dest->data, resBuf, resPos * 2);
		} else
			break;
	} while (1);

	free(resBuf);
}
Beispiel #4
0
void processMainLists(FILE *inf, CptObj *destArr, uint16 *idList) {
	char line[1024];
	dofgets(line, 1024, inf);
	assert(lineMatchSection(line, "MAINLISTS"));
	uint16 *resBuf = (uint16 *)malloc(MAX_OBJ_SIZE);
	uint32 idNum = 0;
	do {
		dofgets(line, 1024, inf);
		if (!isEndOfSection(line)) {
			char cptName[50];
			uint16 id = getInfo(line, "MAINLST", cptName);
			CptObj *dest = destArr + id;
			assertEmpty(dest);
			dest->type = MAINLIST;
			dest->dbgName = (char *)malloc(strlen(cptName) + 1);
			strcpy(dest->dbgName, cptName);
			memset(resBuf, 0, MAX_OBJ_SIZE);
			uint32 resPos = 0;
			idList[idNum] = id;
			idNum++;

			do {
				dofgets(line, 1024, inf);
				if (!isEndOfObject(line, "MAINLST", id)) {
					assert((line[0] == '\t') && (line[1] == '\t'));
					char *stopCh;
					uint16 destId = (uint16)strtoul(line + 2, &stopCh, 16);
					assert(stopCh == (line + 6));
					assert((stopCh[0] == ':') && (stopCh[1] == ':'));
                    resBuf[resPos] = destId;
					resPos++;
				} else
					break;
			} while (1);
			assert(resPos < (MAX_OBJ_SIZE / 2));
			dest->len = resPos;
			dest->data = (uint16 *)malloc(resPos * 2);
			memcpy(dest->data, resBuf, resPos * 2);
		} else
			break;
	} while (1);

	free(resBuf);
}
Beispiel #5
0
void processBins(FILE *inf, CptObj *destArr, const char *typeName, const char *objName, uint8 cTypeId) {
	char line[1024];
	dofgets(line, 1024, inf);
	assert(lineMatchSection(line, typeName));
	uint16 *resBuf = (uint16 *)malloc(MAX_OBJ_SIZE);
	do {
		dofgets(line, 1024, inf);
		if (!isEndOfSection(line)) {
			char cptName[50];
			uint16 id = getInfo(line, objName, cptName);
			CptObj *dest = destArr + id;
			assertEmpty(dest);
			dest->dbgName = (char *)malloc(strlen(cptName) + 1);
			dest->type = cTypeId;
			strcpy(dest->dbgName, cptName);
			memset(resBuf, 0, MAX_OBJ_SIZE);
			uint32 resPos = 0;

			do {
				dofgets(line, 1024, inf);
				if (!isEndOfObject(line, objName, id)) {
					assert((line[0] == '\t') && (line[1] == '\t'));
					char *stopCh;
					uint16 destId = (uint16)strtoul(line + 2, &stopCh, 16);
					assert(stopCh == (line + 6));
					assert(*stopCh == '\0');
                    resBuf[resPos] = destId;
					resPos++;
				} else
					break;
			} while (1);
			assert(resPos < (MAX_OBJ_SIZE / 2));
			dest->len = resPos;
			dest->data = (uint16 *)malloc(resPos * 2);
			memcpy(dest->data, resBuf, resPos * 2);
		} else
			break;
	} while (1);

	free(resBuf);
}
Beispiel #6
0
void TestSuite::TestString(void){
    UnitTest::SetPrefix("TestString.cpp - Test String Class");
    {
	   json_string s;
	   assertEmpty(s);
    }

    {
	   json_string s;
	   assertEmpty(s);
	   json_string m(s);
	   assertEmpty(m);
	   assertEmpty(s);
	   assertSame(s, m);
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   assertEquals(s.length(), 5);
	   assertFalse(s.empty());
	   assertCStringSame(s.c_str(), JSON_TEXT("hello"));
	   assertEquals(s, s);
	   assertEquals(s, JSON_TEXT("hello"));
	   s.clear();
	   assertEmpty(s);
    }

    {
	   json_string s(5, 'h');
	   assertEquals(s.length(), 5);
	   assertFalse(s.empty());
	   assertCStringSame(s.c_str(), JSON_TEXT("hhhhh"));
	   assertEquals(s, s);
	   assertEquals(s, JSON_TEXT("hhhhh"));
	   s.clear();
	   assertEmpty(s);
    }

    {
	   json_string s(5, 'h');
	   json_string m(s);
	   assertSame(s, m);
    }

    {
	   json_string s(5, 'h');
	   json_string m(s);
	   assertSame(s, m);
	   s.clear();
	   assertEmpty(s);
	   assertEquals(s.length(), 0);
	   assertDifferent(s, m);
    }


    {
	   json_string s(JSON_TEXT("hello"));
	   json_string m = s;
	   assertSame(s, m);
	   m = s.substr(1, 3);
	   assertEquals(m.length(), 3);
	   assertEquals(m, JSON_TEXT("ell"));
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   json_string m = s;
	   assertSame(s, m);
	   m = s.substr(1);
	   assertEquals(m.length(), 4);
	   assertEquals(m, JSON_TEXT("ello"));
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   s += JSON_TEXT(" world");
	   assertEquals(s.length(), 11);
	   assertEquals(s, JSON_TEXT("hello world"));
    }


    {
	   json_string s(JSON_TEXT("hello"));
	   json_string m = s + JSON_TEXT(" world ") + s;
	   assertEquals(m.length(), 17);
	   assertEquals(m, JSON_TEXT("hello world hello"));
    }

    {
	   json_string s(JSON_TEXT("hello"));
	   s += 'a';
	   s += 'a';
	   s += 'a';
	   s += 'a';
	   assertEquals(s.length(), 9);
	   assertEquals(s, JSON_TEXT("helloaaaa"));
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find('w');
	   assertEquals(pos, 6);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find('z');
	   assertEquals(pos, json_string::npos);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find_first_not_of(JSON_TEXT("helo"));
	   assertEquals(pos, 5);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   size_t pos = s.find_first_of(JSON_TEXT("ol"));
	   assertEquals(pos, 2);
    }

    {
	   json_string s(JSON_TEXT("hello world"));
	   s.erase(s.begin(), s.begin() + 3);
	   assertEquals(s, JSON_TEXT("lo world"));
    }

	{
	   json_string s(JSON_TEXT("hello world"), 5);
	   assertEquals(s, JSON_TEXT("hello"));
    }

    #ifndef JSON_STRING_HEADER
        {
	        json_string s(JSON_TEXT("hello world"));
	        std::wstring wtest(L"hello world");
	        std::string stest("hello world");
	        assertEquals(libjson::to_std_string(s), stest);
	        assertEquals(stest, libjson::to_std_string(s));
	        assertEquals(libjson::to_std_wstring(s), wtest);
	        assertEquals(wtest, libjson::to_std_wstring(s));

	        assertEquals(s, libjson::to_json_string(stest));
	        assertEquals(libjson::to_json_string(stest), s);
	        assertEquals(s, libjson::to_json_string(wtest));
	        assertEquals(libjson::to_json_string(wtest), s);
        }
    #endif
}