コード例 #1
0
void TestMapBlockAddDuplicate(void)
{
	CMapBlock	cMapBlock;
	int			ia = 'a';
	int			ib = 'a';
	BOOL		bResult;
	int			iWorldLen;
	int			iHelloLen;

	iWorldLen = strlen("World");
	iHelloLen = strlen("Hello");

	cMapBlock.Init(1024, &CompareInt, TRUE);
	bResult = cMapBlock.Put(&ia, sizeof(int), "Hello", iHelloLen + 1);
	AssertTrue(bResult);
	AssertInt(1, cMapBlock.NumElements());
	AssertString("Hello", (char*)cMapBlock.Get(&ia));

	bResult = cMapBlock.Put(&ib, sizeof(int), "World", iWorldLen + 1);
	AssertTrue(bResult);
	AssertInt(1, cMapBlock.NumElements());
	AssertString("World", (char*)cMapBlock.Get(&ia));

	cMapBlock.Kill();
}
コード例 #2
0
void TestFileUtilTouchDirectory(void)
{
	CFileUtil		cFileUtil;
	CChars			szDirectory;
	CChars			szFileName;

	cFileUtil.RemoveDir("file_util");

	szDirectory.Init("file_util" _FS_ "directory" _FS_ "make" _FS_ "test");
	cFileUtil.FullPath(&szDirectory);
	szFileName.Init(szDirectory);
	cFileUtil.AppendToPath(&szFileName, "Warthog.PIG");
	AssertTrue(cFileUtil.TouchDir(szFileName.Text()));
	AssertTrue(cFileUtil.Touch(szFileName.Text()));

	szDirectory.Kill();
	szFileName.Kill();

	cFileUtil.RemoveDir("file_util");

	AssertFalse(cFileUtil.TouchDir("C:\\Warthog.PIG"));
	AssertFalse(cFileUtil.TouchDir("\\Warthog.PIG"));

	szDirectory.Init();
	cFileUtil.CurrentDirectory(&szDirectory);
	szDirectory.Append("War-pig.hog");
	AssertFalse(cFileUtil.TouchDir(szDirectory.Text()));
	szDirectory.Kill();
}
コード例 #3
0
ファイル: testaudio.c プロジェクト: CliffsDover/wesnoth_ios
/**
 * \brief Negative tests around enumeration and naming of audio devices.
 * 
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
 * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
 */
int audio_enumerateAndNameAudioDevicesNegativeTests()
{
   int ret;
   int t;
   int i, j, no, nc;
   const char *name;
      
   /* Get number of devices. */
   no = SDL_GetNumAudioDevices(0);
   nc = SDL_GetNumAudioDevices(1);
   
   /* Invalid device index when getting name */
   for (t=0; t<2; t++) {
      /* Negative device index */
      i = -1;
      name = SDL_GetAudioDeviceName(i, t);
      AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
      
      /* Device index past range */
      for (j=0; j<3; j++) {
         i = (t) ? nc+j : no+j;
         name = SDL_GetAudioDeviceName(i, t);
         AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
      }
      
      /* Capture index past capture range but within output range */
      if ((no>0) && (no>nc) && (t==1)) {
         i = no-1;
         name = SDL_GetAudioDeviceName(i, t);
         AssertTrue(name == NULL, "SDL_GetAudioDeviceName(%i, %i): returned a name, should return NULL", i, t);
      }
   }
}
コード例 #4
0
ファイル: DictTestUtils.hpp プロジェクト: jy4618272/OpenCC
 static void TestDict(DictPtr dict) {
   Optional<DictEntry> entry;
   entry = dict->MatchPrefix("BYVoid");
   AssertTrue(!entry.IsNull());
   AssertEquals("BYVoid", entry.Get().key);
   AssertEquals("byv", entry.Get().GetDefault());
   
   entry = dict->MatchPrefix("BYVoid123");
   AssertTrue(!entry.IsNull());
   AssertEquals("BYVoid", entry.Get().key);
   AssertEquals("byv", entry.Get().GetDefault());
   
   entry = dict->MatchPrefix(utf8("積羽沉舟"));
   AssertTrue(!entry.IsNull());
   AssertEquals(utf8("積羽沉舟"), entry.Get().key);
   AssertEquals(utf8("羣輕折軸"), entry.Get().GetDefault());
   
   entry = dict->MatchPrefix("Unknown");
   AssertTrue(entry.IsNull());
   
   const vector<DictEntry> matches = dict->MatchAllPrefixes(utf8("清華大學計算機系"));
   AssertEquals(3, matches.size());
   AssertEquals(utf8("清華大學"), matches.at(0).key);
   AssertEquals("TsinghuaUniversity", matches.at(0).GetDefault());
   AssertEquals(utf8("清華"), matches.at(1).key);
   AssertEquals("Tsinghua", matches.at(1).GetDefault());
   AssertEquals(utf8("清"), matches.at(2).key);
   AssertEquals("Tsing", matches.at(2).GetDefault());
 }
コード例 #5
0
void TestIndexTreeMemoryPutPtrDuplicate(void)
{
	CIndexTreeMemory		cIndex;
	CTestIndexTreeObject	andrew;
	CTestIndexTreeObject	andrewToo;
	CTestIndexTreeObject**	pcResult;
	CArrayVoidPtr			avp;
	BOOL					bResult;

	cIndex.Init();

	andrew.Init("Andrew");
	bResult = cIndex.PutPtr(andrew.mszName, &andrew);
	AssertTrue(bResult);
	AssertTrue(cIndex.ValidateSize());
	AssertInt(1, cIndex.NumElements());

	andrewToo.Init("Andrew");
	bResult = cIndex.PutPtr(andrewToo.GetName(), &andrewToo);
	AssertTrue(bResult);
	AssertTrue(cIndex.ValidateSize());
	AssertInt(1, cIndex.NumElements());

	pcResult = (CTestIndexTreeObject**)cIndex.Get("Andrew");
	AssertPointer(&andrewToo, *pcResult);

	avp.Init();
	cIndex.FindAll(&avp);
	AssertInt(1, avp.NumElements());
	avp.Kill();

	cIndex.Kill();
}
コード例 #6
0
void TestIndexesAddAndRemove(void)
{
	CIndexes			cIndexes;
	void*				pvMem;
	int					i;

	i = 391287491;
	pvMem = &i;

	cIndexes.Init(512);
	AssertInt(0, (int)cIndexes.NumIndexed());
	
	cIndexes.Add(1, pvMem);
	AssertInt(1, (int)cIndexes.NumIndexed());

	cIndexes.Remove(1);
	AssertInt(0, (int)cIndexes.NumIndexed());
	AssertTrue(cIndexes.TestTopIsEmpty());

	cIndexes.Add(1, pvMem);
	AssertInt(1, (int)cIndexes.NumIndexed());

	cIndexes.Remove(1);
	AssertInt(0, (int)cIndexes.NumIndexed());
	AssertTrue(cIndexes.TestTopIsEmpty());

	cIndexes.Kill();
}
コード例 #7
0
static int test_find_one_input_for_xor(OE oe) {
	CircuitVisitor cv = 0;
	CircuitParser cp = 0;
	Tokenizer tk = 0;
	List circuit = 0;
	Map input_gates = 0;
	List address_of_input_gates = 0;
	Gate g = 0;
	_Bool ok = 0;

	tk = FunCallTokenizer_New(oe);
	cp = CircuitParser_New(oe, tk);
	circuit = cp->parseSource((byte*)"XOR(0,1,1)",11);

	cv = InputGateVisitor_New(oe);
	input_gates = cv->visit(circuit);

	AssertTrue(input_gates != 0)
	address_of_input_gates = input_gates->get_keys();

	AssertTrue(((uint)address_of_input_gates->get_element(0) == 1));

	InputGateVisitor_Destroy(&cv);
	SingleLinkedList_destroy(&address_of_input_gates);

test_end:
	return ok;
}
コード例 #8
0
ファイル: api.c プロジェクト: UNIVERSAL-IT-SYSTEMS/cyassl
static void test_server_CyaSSL_new(void)
{
#if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
    CYASSL_CTX *ctx;
    CYASSL_CTX *ctx_nocert;
    CYASSL *ssl;

    AssertNotNull(ctx_nocert = CyaSSL_CTX_new(CyaSSLv23_server_method()));
    AssertNotNull(ctx        = CyaSSL_CTX_new(CyaSSLv23_server_method()));

    AssertTrue(CyaSSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM));
    AssertTrue(CyaSSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM));

    /* invalid context */
    AssertNull(ssl = CyaSSL_new(NULL));
    AssertNull(ssl = CyaSSL_new(ctx_nocert));

    /* success */
    AssertNotNull(ssl = CyaSSL_new(ctx));

    CyaSSL_free(ssl);
    CyaSSL_CTX_free(ctx);
    CyaSSL_CTX_free(ctx_nocert);
#endif
}
コード例 #9
0
void TestChunkFileMD5ing(void)
{
	char			szFox[] = "The quick brown fox jumps over the lazy dog";
	unsigned char	ucFoxMD5[] = {0x9e, 0x10, 0x7d, 0x9d, 0x37, 0x2b, 0xb6, 0x82, 0x6b, 0xd8, 0x1d, 0x35, 0x42, 0xa4, 0x19, 0xd6};
	int				iFoxLen;
	char			szLorem[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
	unsigned char	ucLoremMD5[] = {0xfa, 0x5c, 0x89, 0xf3, 0xc8, 0x8b, 0x81, 0xbf, 0xd5, 0xe8, 0x21, 0xb0, 0x31, 0x65, 0x69, 0xaf};
	int				iLoremLen;
	CChunkFile		cChunkFile;

	iFoxLen = (int)strlen(szFox);
	iLoremLen = (int)strlen(szLorem);

	cChunkFile.Init(MemoryFile());
	AssertTrue(cChunkFile.WriteOpen());
	AssertTrue(cChunkFile.WriteChunkBegin());
	AssertTrue(cChunkFile.Write(szFox, 1, iFoxLen) > 0);
	AssertTrue(cChunkFile.WriteChunkEnd("ChunkName"));
	AssertTrue(cChunkFile.Write(szLorem, 1, iLoremLen) > 0);
	AssertTrue(cChunkFile.WriteClose());

	AssertTrue(cChunkFile.ReadOpen());
	AssertMD5(ucLoremMD5, (unsigned char *)cChunkFile.GetMD5Hash());
	AssertTrue(cChunkFile.ReadChunkBegin(0));
	AssertMD5(ucFoxMD5, (unsigned char *)cChunkFile.GetMD5Hash());
	AssertTrue(cChunkFile.ReadChunkEnd());
	AssertTrue(cChunkFile.ReadClose());

	cChunkFile.Kill();
}
コード例 #10
0
void TestIndexTreeBlockMemoryRemoveByObject(void)
{
	CIndexTreeBlockMemory	cIndex;
	CTestIndexTreeObject	object1;
	CTestIndexTreeObject	object2;
	CTestIndexTreeObject	object3;
	CTestIndexTreeObject**	ppcRemoved;

	cIndex.Init();

	AssertInt(1, cIndex.CountAllocatedNodes());

	object1.Init("denarii");
	cIndex.PutPtr(object1.GetName(), &object1);
	AssertInt(8, cIndex.CountAllocatedNodes());

	object2.Init("dendrodra");
	cIndex.PutPtr(object2.GetName(), &object2);

	object3.Init("dendrons");
	cIndex.PutPtr(object3.GetName(), &object3);

	AssertInt(3, cIndex.NumElements());
	ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object2.GetName());
	AssertPointer(&object2, *ppcRemoved);
	AssertTrue(cIndex.Remove(object2.GetName()));
	ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object2.GetName());
	AssertNull(ppcRemoved);
	AssertInt(2, cIndex.NumElements());
	AssertFalse(cIndex.Remove(object2.GetName()));
	AssertInt(2, cIndex.NumElements());

	AssertInt(13, cIndex.CountAllocatedNodes());
	cIndex.Remove(object3.GetName());

	AssertInt(1, cIndex.NumElements());
	AssertInt(8, cIndex.CountAllocatedNodes());

	cIndex.PutPtr(object3.GetName(), &object3);
	AssertInt(13, cIndex.CountAllocatedNodes());

	AssertInt(2, cIndex.NumElements());
	ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object3.GetName());
	AssertPointer(&object3, *ppcRemoved);
	AssertTrue(cIndex.Remove(object3.GetName()));
	ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object3.GetName());
	AssertNull(ppcRemoved);
	AssertInt(1, cIndex.NumElements());
	ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object1.GetName());
	AssertPointer(&object1, *ppcRemoved);
	AssertTrue(cIndex.Remove(object1.GetName()));
	ppcRemoved = (CTestIndexTreeObject**)cIndex.Get(object1.GetName());
	AssertNull(ppcRemoved);
	AssertInt(0, cIndex.NumElements());

	AssertFalse(cIndex.Remove(NULL));
	AssertFalse(cIndex.Remove(""));

	cIndex.Kill();
}
コード例 #11
0
void TestSetTypeInstantiation(void)
{
	UnknownsInit();

	CSetType<CTestUnknown>	cSet;
	CTestUnknown*			pcTest1;
	CTestUnknown*			pcTest2;
	CTestUnknown*			pcTest;
	int						iSize;
	char*					szName;
	SSetIterator			sIter;
	int						iCount;

	cSet.Init();

	pcTest1 = cSet.Add();
	pcTest1->Init();
	pcTest2 = UMalloc(CTestUnknown);
	pcTest2->Init();
	cSet.Add(pcTest2);

	iCount = 0;
	pcTest = cSet.StartIteration(&sIter);
	while (pcTest)
	{
		iCount++;
		pcTest = cSet.Iterate(&sIter);
	}
	AssertInt(2, iCount);
	AssertInt(2, cSet.NumElements());

	//This test is not correct.  The order is not guaranteed.
	//However it necessary to make the template compile.
	AssertTrue(cSet.Contains(pcTest1));
	AssertTrue(cSet.Contains(pcTest2));

	pcTest = cSet.StartIteration(&sIter);
	AssertPointer(pcTest1, pcTest);
	pcTest = cSet.Iterate(&sIter);
	AssertPointer(pcTest2, pcTest);

	pcTest = cSet.StartIteration(&sIter);
	cSet.RemoveDuringIteration(&sIter);
	pcTest = cSet.Iterate(&sIter);
	AssertPointer(pcTest2, pcTest);

	AssertInt(1, cSet.NumElements());

	cSet.Remove(pcTest2);
	AssertInt(0, cSet.NumElements());

	iSize = cSet.ClassSize();
	AssertInt(40, iSize);

	szName = cSet.ClassName();
	AssertString("CSetType", szName);

	cSet.Kill();
	UnknownsKill();
}
コード例 #12
0
ファイル: Auphonic.cpp プロジェクト: Ultraschall/Legacy
template<> const std::string&& MediaItem_GetProperty(MediaItem* item, const char* property)
{
   AssertTrue(item != 0);
   AssertTrue(property != 0);
      
   char* resultPtr = reinterpret_cast<char*>(GetSetMediaItemInfo(item, property, 0));
   std::string value(resultPtr);
   return std::move(value);
}
コード例 #13
0
ファイル: Auphonic.cpp プロジェクト: Ultraschall/Legacy
template<> const std::string&& MediaTrack_GetProperty(MediaTrack* track, const char* property)
{
   AssertTrue(track != 0);
   AssertTrue(property != 0);
      
   char* resultPtr = reinterpret_cast<char*>(GetSetMediaTrackInfo(track, property, 0));
   std::string value(resultPtr);
   return std::move(value);
}
コード例 #14
0
void TestDehollowficationFromDatabaseOfTwoPointers(void)
{
	CIndexedConfig	cConfig;
	CFileUtil		cFileUtil;

	cConfig.Manual("Output\\Dehollowfication\\Database",
		FALSE,
		TRUE,
		FALSE,
		1 MB);

	cFileUtil.RemoveDir("Output\\Dehollowfication\\Database");

	MemoryInit();
	ObjectsInit(&cConfig);
	SetupDehollowficationScene();
	gcObjects.Flush(FALSE, FALSE);
	ObjectsKill();
	MemoryKill();

	MemoryInit();
	ObjectsInit(&cConfig);
	SetupDehollowficationConstructors();

	Ptr<CRoot> pRoot = ORoot();
	Ptr<CTestDoubleNamedString> pDouble = pRoot->Get<CTestDoubleNamedString>("Double Start");

	Ptr<CTestNamedString> pString1 = pDouble->mpSplit1;
	Ptr<CTestNamedString> pString2 = pDouble->mpSplit2;
	pString1->ClassName();
	pString2->ClassName();

	Ptr<CTestNamedString> pDiamond1 = pString1->mpAnother;
	Ptr<CTestNamedString> pDiamond2 = pString2->mpAnother;

	AssertTrue(pDiamond1.IsHollow());
	AssertTrue(pDiamond2.IsHollow());
	AssertPointer(pDiamond1.Object(), pDiamond2.Object());
	AssertPointer(pString1->mpAnother.Object(), pString2->mpAnother.Object());
	AssertLongLongInt(3LL, pDiamond1.GetIndex());
	AssertLongLongInt(3LL, pDiamond2.GetIndex());

	//Dehollofication of pDiamond1 happens here. pString1->mpAnother and pString2->mpAnother are remapped to the dehollowed diamond object.
	pDiamond1->ClassName();

	AssertFalse(pDiamond1.IsHollow());
	AssertFalse(pDiamond2.IsHollow());  //This should be false but it's not until I remap local pointers.
	AssertPointer(pDiamond1.Object(), pDiamond2.Object());  //These should be the same but they're not until I remap local pointers.
	AssertLongLongInt(3LL, pDiamond1.GetIndex());

	AssertFalse(pString1->mpAnother.IsHollow());
	AssertFalse(pString2->mpAnother.IsHollow());
	AssertPointer(pString1->mpAnother.Object(), pString2->mpAnother.Object());

	ObjectsKill();
	MemoryKill();
}
コード例 #15
0
void TestArrayCopy(void)
{
	CTestArray					asTestArray;
	CTestArray					asDestArray;
	STestArrayTemplateItem*		psItem;
	void*						pvDest1;
	void*						pvDest2;
	BOOL						bResult;

	asTestArray.Init(5);
	psItem = asTestArray.Add();
	psItem->i1 = psItem->i2 = 8;
	psItem = asTestArray.Add();
	psItem->i1 = psItem->i2 = 5;
	psItem = asTestArray.Add();
	psItem->i1 = psItem->i2 = 7;
	psItem = asTestArray.Add();
	psItem->i1 = psItem->i2 = 2;
	psItem = asTestArray.Add();
	psItem->i1 = psItem->i2 = 1;

	asDestArray.Init(1);
	bResult = asDestArray.Copy(&asTestArray);
	AssertTrue(bResult);
	pvDest1 = asDestArray.GetData();

	bResult = asDestArray.Copy(&asTestArray);
	AssertFalse(bResult);
	pvDest2 = asDestArray.GetData();
	AssertTrue(pvDest1 == pvDest2);

	psItem = asTestArray.Add();
	psItem->i1 = psItem->i2 = 3;

	bResult = asDestArray.Copy(&asTestArray);
	AssertTrue(bResult);
	
	AssertInt(10, asDestArray.AllocatedElements());
	AssertInt(6, asDestArray.NumElements());

	psItem = asDestArray.Get(0);
	AssertInt(8, psItem->i1);
	psItem = asDestArray.Get(1);
	AssertInt(5, psItem->i1);
	psItem = asDestArray.Get(2);
	AssertInt(7, psItem->i1);
	psItem = asDestArray.Get(3);
	AssertInt(2, psItem->i1);
	psItem = asDestArray.Get(4);
	AssertInt(1, psItem->i1);
	psItem = asDestArray.Get(5);
	AssertInt(3, psItem->i1);

	asTestArray.Kill();
	asDestArray.Kill();
}
コード例 #16
0
void TestTreeTemplateFileHelper(void)
{
	CTestTree				cTree;
	STestTreeTemplateItem*	psRoot;
	STestTreeTemplateItem*	psChild1;
	STestTreeTemplateItem*	psChild2;
	CMemoryFile*			pcMemoryFile;
	CFileBasic				cFileBasic;
	BOOL					bResult;

	cTree.Init();

	psRoot = cTree.InsertRoot();
	psRoot->mi1 = 5; psRoot->mi2 = 7;

	psChild1 = cTree.InsertOnRightOfChildren(psRoot);
	psChild1->mi1 = 1; psChild1->mi2 = 2;

	psChild2 = cTree.InsertOnRightOfChildren(psRoot);
	psChild2->mi1 = 3; psChild2->mi2 = 9;

	pcMemoryFile = MemoryFile();
	pcMemoryFile->mbBasicFileMustFree = FALSE;

	cFileBasic.Init(pcMemoryFile);
	cFileBasic.Open(EFM_Write_Create);
	bResult = cTree.WriteTreeTemplate(&cFileBasic);
	AssertTrue(bResult);
	cFileBasic.Close();
	cFileBasic.Kill();

	cTree.Kill();

	cFileBasic.Init(pcMemoryFile);
	cFileBasic.Open(EFM_Read);
	bResult = cTree.ReadTreeTemplate(&cFileBasic);
	AssertTrue(bResult);
	cFileBasic.Close();
	cFileBasic.Kill();

	free(pcMemoryFile);

	psRoot = cTree.GetRoot();
	AssertInt(5, psRoot->mi1);
	AssertInt(7, psRoot->mi2);

	psChild1 = cTree.GetUp(psRoot);
	AssertInt(1, psChild1->mi1);
	AssertInt(2, psChild1->mi2);

	psChild2 = cTree.GetRight(psChild1);
	AssertInt(3, psChild2->mi1);
	AssertInt(9, psChild2->mi2);

	cTree.Kill();
}
コード例 #17
0
ファイル: testaudio.c プロジェクト: CliffsDover/wesnoth_ios
/**
 * @brief Checks current audio driver name with initialized audio.
 */
int audio_printCurrentAudioDriver()
{
   int ret;
   const char *name;

   /* Check current audio driver */
   name = SDL_GetCurrentAudioDriver();
   AssertTrue(name != NULL, "name != NULL");
   AssertTrue(strlen(name)>0, "name empty");
}
コード例 #18
0
void TestIndexTreeMemoryAdd(void)
{
	CIndexTreeMemory		cIndex;
	CTestIndexTreeObject	a;
	CTestIndexTreeObject	aa;
	CTestIndexTreeObject	temp;
	CArrayVoidPtr			avp;
	BOOL					bResult;
	CIndexTreeNodeMemory*	pcNode;
	CTestIndexTreeObject**	ppvTest;
	CTestIndexTreeObject***	ppvTestA;
	CTestIndexTreeObject***	ppvTestAA;

	cIndex.Init();
	a.Init("A");
	bResult = cIndex.PutPtr(a.GetName(), &a);
	AssertTrue(bResult);

	pcNode = cIndex.GetNode("A", 1);
	ppvTest = (CTestIndexTreeObject**)pcNode->GetObjectPtr();
	AssertPointer(&a, *ppvTest);

	aa.Init("AA");
	bResult = cIndex.PutPtr(aa.GetName(), &aa);
	AssertTrue(bResult);

	pcNode = cIndex.GetNode("A", 1);
	ppvTest = (CTestIndexTreeObject**)pcNode->GetObjectPtr();
	AssertPointer(&a, *ppvTest);

	pcNode = cIndex.GetNode("AA", 2);
	ppvTest = (CTestIndexTreeObject**)pcNode->GetObjectPtr();
	AssertPointer(&aa, *ppvTest);

	avp.Init();
	cIndex.FindAll(&avp);
	AssertInt(2, avp.NumElements());
	ppvTestA = (CTestIndexTreeObject***)avp.Get(0);
	ppvTestAA = (CTestIndexTreeObject***)avp.Get(1);
	AssertPointer(&a, **ppvTestA);
	AssertPointer(&aa, **ppvTestAA);
	AssertString("A", (**ppvTestA)->mszName);
	AssertString("AA", (**ppvTestAA)->mszName);

	avp.Kill();
	cIndex.Kill();

	cIndex.Init();
	bResult = cIndex.PutPtr(NULL, &temp);
	AssertFalse(bResult);
	bResult = cIndex.PutPtr("", &temp);
	AssertFalse(bResult);

	cIndex.Kill();
}
コード例 #19
0
void TestChunkFileSimple(void)
{
	CChunkFile	cChunkFile;
	CFileUtil	cFileUtil;
	int			iChunkNum;
	
	cFileUtil.MakeDir("Output");
	cFileUtil.Delete("Output/ChunkFile.bin");
	cChunkFile.Init(DiskFile("Output/ChunkFile.bin"));
	AssertFalse(cChunkFile.IsOpen());
	AssertTrue(cChunkFile.WriteOpen());
	AssertTrue(cChunkFile.IsOpen());
	AssertTrue(cChunkFile.WriteChunkBegin());
	AssertTrue(cChunkFile.WriteChunkEnd("ThisChunk"));
	AssertTrue(cChunkFile.WriteClose());
	AssertFalse(cChunkFile.IsOpen());
	cChunkFile.Kill();

	cChunkFile.Init(DiskFile("Output/ChunkFile.bin"));
	AssertFalse(cChunkFile.IsOpen());
	AssertTrue(cChunkFile.ReadOpen());
	AssertTrue(cChunkFile.IsOpen());
	iChunkNum = cChunkFile.FindFirstChunkWithName("ThisChunk");
	AssertInt(0, iChunkNum);
	AssertTrue(cChunkFile.ReadChunkBegin(iChunkNum));
	AssertTrue(cChunkFile.ReadClose());
	AssertFalse(cChunkFile.IsOpen());
	cChunkFile.Kill();
}
コード例 #20
0
void TestObjectReaderSimpleDeserialised(void)
{
	WriteObjectReaderSimpleFile();

	CObjectReaderSimpleDisk		cReader;
	CObjectGraphDeserialiser	cGraphDeserialiser;
	CPointer					cBase;

	Ptr<CTestNamedString>		cNS1;
	Ptr<CTestNamedString>		cNS2;
	CPointer					cTemp;

	CObjectAllocator			cAllocator;
	CDependentReadObjects		cDependentReadObjects;

	MemoryInit();
	ObjectsInit();

	gcObjects.AddConstructor<CTestNamedString>();

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumMemoryIndexes());

	cAllocator.Init(&gcObjects);
	cDependentReadObjects.Init();
	cReader.Init("Output\\ObjectReaderSimple\\Test\\");
	cGraphDeserialiser.Init(&cReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory());
	cBase = cGraphDeserialiser.Read("Waggy");

	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());

	cNS1 = gcObjects.Get("Waggy");
	AssertTrue(cNS1.IsNotNull());
	AssertString("NS1", cNS1->mszEmbedded.Text());

	cNS2 = gcObjects.Get("Dog");
	AssertTrue(cNS2.IsNotNull());
	AssertString("NS2", cNS2->mszEmbedded.Text());

	AssertTrue(cBase.IsNotNull());
	AssertString("CTestNamedString", cBase->ClassName());
	AssertPointer(&cNS1, &cBase);

	AssertPointer(&cNS2, &cNS1->mpAnother);
	AssertPointer(NULL, &cNS2->mpAnother);

	cGraphDeserialiser.Kill();
	cDependentReadObjects.Kill();
	cAllocator.Kill();
	cReader.Kill();

	ObjectsKill();
}
コード例 #21
0
ファイル: Auphonic.cpp プロジェクト: Ultraschall/Legacy
template<class T> const T&& MediaItem_GetProperty(MediaItem* item, const char* property)
{
   AssertTrue(item != 0);
   AssertTrue(property != 0);
      
   T* resultPointer = reinterpret_cast<T*>(GetSetMediaItemInfo(item, property, 0));
   AssertTrue(resultPointer != 0);
      
   T value = *resultPointer;
   return std::move(value);
}
コード例 #22
0
ファイル: Auphonic.cpp プロジェクト: Ultraschall/Legacy
template<class T> const T&& MediaTrack_GetProperty(MediaTrack* track, const char* property)
{
   AssertTrue(track != 0);
   AssertTrue(property != 0);
      
   T* resultPointer = reinterpret_cast<T*>(GetSetMediaTrackInfo(track, property, 0));
   AssertTrue(resultPointer != 0);
      
   T value = *resultPointer;
   return std::move(value);
}
コード例 #23
0
ファイル: api.c プロジェクト: UNIVERSAL-IT-SYSTEMS/cyassl
static void test_CyaSSL_read_write(void)
{
#ifdef HAVE_IO_TESTS_DEPENDENCIES
    /* The unit testing for read and write shall happen simutaneously, since
     * one can't do anything with one without the other. (Except for a failure
     * test case.) This function will call all the others that will set up,
     * execute, and report their test findings.
     *
     * Set up the success case first. This function will become the template
     * for the other tests. This should eventually be renamed
     *
     * The success case isn't interesting, how can this fail?
     * - Do not give the client context a CA certificate. The connect should
     *   fail. Do not need server for this?
     * - Using NULL for the ssl object on server. Do not need client for this.
     * - Using NULL for the ssl object on client. Do not need server for this.
     * - Good ssl objects for client and server. Client write() without server
     *   read().
     * - Good ssl objects for client and server. Server write() without client
     *   read().
     * - Forgetting the password callback?
    */
    tcp_ready ready;
    func_args client_args;
    func_args server_args;
    THREAD_TYPE serverThread;

#ifdef CYASSL_TIRTOS
    fdOpenSession(Task_self());
#endif

    StartTCP();
    InitTcpReady(&ready);
    
    server_args.signal = &ready;
    client_args.signal = &ready;
    
    start_thread(test_server_nofail, &server_args, &serverThread);
    wait_tcp_ready(&server_args);
    test_client_nofail(&client_args);
    join_thread(serverThread);

    AssertTrue(client_args.return_code);
    AssertTrue(server_args.return_code);

    FreeTcpReady(&ready);

#ifdef CYASSL_TIRTOS
    fdOpenSession(Task_self());
#endif

#endif
}
コード例 #24
0
void TestVirtualCall(void)
{
	MemoryInit();
	UnknownsInit();

	CTestObjectIsListenerWithEvent*		pcTest;
	CTestObjectIsListener*				pcListener;
	CTestAnotherListener				cAnother1;
	CTestAnotherListener				cAnother2;
	CTestAnotherListener				cAnother3;
	BOOL								bResult;

	pcTest = UMalloc(CTestObjectIsListenerWithEvent);
	pcTest->Init();

	pcListener = UMalloc(CTestObjectIsListener);
	pcListener->Init();

	AssertInt(WH_SomeOneSetUpUsTheBomb, pcTest->meWhatHappen);
	AssertString("Nothing to see here", pcListener->mszAlsoBored.Text());
	AssertInt(0, pcTest->miBored);

	bResult = pcTest->AddListener<CTestListener>(pcListener);
	AssertTrue(bResult);
	bResult = pcTest->AddListener(&cAnother1);
	AssertTrue(bResult);
	bResult = pcTest->AddListener(&cAnother2);
	AssertTrue(bResult);

	pcTest->MakeEventStyle1Happen();
	AssertInt(WH_WeGetSignal, pcTest->meWhatHappen);
	AssertString("Sup my homies", pcListener->mszAlsoBored.Text());
	AssertInt(1, pcTest->miBored);

	pcTest->MakeEventStyle2Happen();
	AssertInt(WH_MoveZigForGreatJustice, pcTest->meWhatHappen);
	AssertString("Wikky wikky free styling", pcListener->mszAlsoBored.Text());
	AssertInt(2, pcTest->miBored);

	pcTest->CallListeners(&CTestAnotherListener::Another, pcTest, NULL);
	AssertInt(1, cAnother1.iThisIsNotTheRightWayToUseListeners);
	AssertInt(1, cAnother2.iThisIsNotTheRightWayToUseListeners);
	AssertInt(0, cAnother3.iThisIsNotTheRightWayToUseListeners);

	bResult = pcTest->AddListener<CTestBadListener>(NULL);
	AssertFalse(bResult);

	pcListener->Kill();
	pcTest->Kill();

	UnknownsKill();
	MemoryKill();
}
コード例 #25
0
void TestObjectDehollowfication(void)
{
	CFileUtil						cFileUtil;
	CPointer						pPointer;
	CTestDoubleNamedString*			pcInternal;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CTestNamedString>			pSingle;
	int								iClassSize;
	OIndex							oiOld;
	OIndex							oiNew;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/Dehollowfication");
	ObjectsInit("Output/Dehollowfication");
	SetupObjectsForDehollowfication();
	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(9, gcObjects.NumDatabaseObjects());
	ObjectsKill();

	ObjectsInit("Output/Dehollowfication");
	SetupObjectsConstructors();
	AssertLongLongInt(9, gcObjects.NumDatabaseObjects());

	AssertTrue(gcObjects.Contains("Double"));

	pPointer = gcObjects.Get("Double");
	AssertNotNull(pPointer.Object());
	AssertString("CTestDoubleNamedString", pPointer.ClassName());

	pcInternal = (CTestDoubleNamedString*)pPointer.Object();
	AssertTrue(pcInternal->mpSplit1.IsNotNull());
	AssertTrue(pcInternal->mpSplit1.IsHollow());
	AssertTrue(pcInternal->mpSplit2.IsNotNull());
	AssertTrue(pcInternal->mpSplit2.IsHollow());

	pDouble = pPointer;

	oiOld = pDouble->mpSplit1.GetIndex();
	AssertTrue(pcInternal->mpSplit1.IsHollow());  //Making sure we haven't de-hollowed the object by calling GetIndex.

	//Problem - An oi of 1 is briefly assigned to the de-hollowed object and then it is reassigned back to its original value.
	iClassSize = pDouble->mpSplit1->ClassSize();  //The method call - ClassSize() - is irrelevant as long as the -> operator on mpSplit1 is invoked.
	AssertTrue(pcInternal->mpSplit1.IsNotNull());
	AssertFalse(pcInternal->mpSplit1.IsHollow());
	AssertInt(sizeof(CTestNamedString), iClassSize);
	AssertString("CTestNamedString", pcInternal->mpSplit1.ClassName());
	oiNew = pDouble->mpSplit1.GetIndex();
	AssertLongLongInt(oiOld, oiNew);

	pSingle = pDouble->mpSplit2;
	AssertTrue(pcInternal->mpSplit2.IsNotNull());
	AssertTrue(pcInternal->mpSplit2.IsHollow());

	ObjectsKill();
}
コード例 #26
0
void TestIndexTreeBlockMemoryReadWrite(void)
{
	CFileBasic				cFile;
	CIndexTreeBlockMemory	cIndex;
	CIndexTreeBlockMemory	cIndexIn;

	cIndex.Init();
	cIndex.Put("AAA", "DENISA", 7);
	cIndex.Put("AA", "FATJETA", 8);
	cIndex.Put("AAB", "ARIANA", 7);
	cIndex.Put("AAC", "GEORGE", 7);
	cIndex.Put("AB", "IRMA", 5);
	cIndex.Put("ABA", "JULIANA", 8);
	cIndex.Put("ABB", "LULE", 5);
	cIndex.Put("C", "VENERA", 7);
	cIndex.Put("DDDD", "PRANVERA", 9);
	cIndex.Put("DD", "PRIMERA", 8);
	AssertInt(14, cIndex.CountAllocatedNodes());
	AssertInt(10, cIndex.RecurseSize());
	AssertInt(10, cIndex.NumElements());
	AssertInt(4, cIndex.GetLargestKeySize());

	cFile.Init(MemoryFile());
	cFile.Open(EFM_Write_Create);
	AssertTrue(cIndex.Write(&cFile));
	cIndex.Kill();
	cFile.Close();

	cFile.Open(EFM_Read);
	AssertTrue(cIndexIn.Read(&cFile));
	cFile.Close();

	AssertInt(14, cIndexIn.CountAllocatedNodes());
	AssertInt(10, cIndexIn.RecurseSize());
	AssertInt(10, cIndexIn.NumElements());
	AssertInt(4, cIndexIn.GetLargestKeySize());
	AssertString("DENISA", (char*)cIndexIn.Get("AAA"));
	AssertString("FATJETA", (char*)cIndexIn.Get("AA"));
	AssertString("ARIANA", (char*)cIndexIn.Get("AAB"));
	AssertString("GEORGE", (char*)cIndexIn.Get("AAC"));
	AssertString("IRMA", (char*)cIndexIn.Get("AB"));
	AssertString("JULIANA", (char*)cIndexIn.Get("ABA"));
	AssertString("LULE", (char*)cIndexIn.Get("ABB"));
	AssertString("VENERA", (char*)cIndexIn.Get("C"));
	AssertString("PRANVERA", (char*)cIndexIn.Get("DDDD"));
	AssertString("PRIMERA", (char*)cIndexIn.Get("DD"));

	cIndexIn.Kill();
}
コード例 #27
0
void TestTreeTemplateInsert(void)
{
	CTestTree				cTree;
	STestTreeTemplateItem*	pcNode0;
	STestTreeTemplateItem*	pcNode00;
	STestTreeTemplateItem*	pcNode01;
	STestTreeTemplateItem*	pcNode02;
	STestTreeTemplateItem*	pcNode000;
	STestTreeTemplateItem*	pcTest;

	cTree.Init();
	pcNode0 = cTree.InsertRoot();
	pcNode0->Init(672, 7645);

	pcNode00 = cTree.InsertOnRightOfChildren(pcNode0);
	pcNode00->Init(720, 6);

	pcNode000 = cTree.InsertOnRightOfChildren(pcNode00);
	pcNode000->Init(325, 28274);

	pcNode01 = cTree.InsertOnRightOfChildren(pcNode0);
	pcNode01->Init(8, 12);

	pcNode02 = cTree.InsertOnRightOfChildren(pcNode0);
	pcNode02->Init(99, 7);

	AssertInt(5, cTree.NumElements());
	pcTest = cTree.GetRoot();
	AssertPointer(pcNode0, pcTest);
	AssertTrue(pcTest->IsOkay(672, 7645));
	pcTest = cTree.GetUp(pcNode0);
	AssertPointer(pcNode00, pcTest);
	AssertTrue(pcTest->IsOkay(720, 6));
	pcTest = cTree.GetUp(pcNode00);
	AssertPointer(pcNode000, pcTest);
	pcTest = cTree.GetRight(pcNode00);
	AssertPointer(pcNode01, pcTest);
	pcTest = cTree.GetRight(pcNode01);
	AssertPointer(pcNode02, pcTest);
	pcTest = cTree.GetRight(pcNode02);
	AssertNull(pcTest);
	AssertNull(cTree.GetUp(pcNode01));
	AssertNull(cTree.GetUp(pcNode02));
	AssertPointer(pcNode0, cTree.GetDown(pcNode00));
	AssertPointer(pcNode0, cTree.GetDown(pcNode01));
	AssertPointer(pcNode0, cTree.GetDown(pcNode02));

	cTree.Kill();
}
コード例 #28
0
void TestLogFileRead(void)
{
	CLogFile*		pcLogFile;
	CMemoryFile*	pcMemoryFile;
	CFileBasic		cFile;
	BOOL			bResult;
	int				iLength;
	char			sz[200];
	filePos			iRead;

	pcMemoryFile = MemoryFile();
	cFile.Init(pcMemoryFile);
	cFile.Open(EFM_Write_Create);
	cFile.WriteString("The suspense is killing me!");
	cFile.Close();

	pcLogFile = LogFile(pcMemoryFile);
	cFile.Init(pcLogFile);

	bResult = cFile.Open(EFM_Read);
	AssertTrue(bResult);

	pcLogFile->Begin();

	bResult = cFile.ReadStringLength(&iLength);
	AssertTrue(bResult);
	AssertInt(28, iLength);
	AssertFalse(cFile.IsEndOfFile());
	bResult = cFile.ReadStringChars(sz, iLength);
	AssertString("The suspense is killing me!", sz);
	AssertTrue(cFile.IsEndOfFile());

	memset(sz, 0, 200);
	bResult = cFile.Seek(20);
	AssertTrue(bResult);
	bResult = cFile.ReadStringChars(sz, 8);
	AssertString("killing ", sz);
	AssertLongLongInt(28, cFile.GetFilePos());
	AssertFalse(cFile.IsEndOfFile());

	memset(sz, 0, 200);
	bResult = cFile.ReadStringChars(sz, 4);
	AssertString("me!", sz);
	AssertLongLongInt(32, cFile.GetFilePos());
	AssertTrue(cFile.IsEndOfFile());

	iRead = cFile.Read(sz, 1, 1);
	AssertLongLongInt(0, iRead);
	AssertLongLongInt(32, cFile.GetFilePos());
	AssertTrue(cFile.IsEndOfFile());

	AssertLongLongInt(32, cFile.GetFilePos());
	AssertTrue(cFile.IsEndOfFile());

	bResult = cFile.Close();
	AssertTrue(bResult);

	cFile.Kill();
}
コード例 #29
0
void TestEmbeddedObjectPointTo(void)
{
	BOOL		bResult;
	CFileUtil	cFileUtil;
	OIndex		oiComplex;
	char*		szClassName;
	
	cFileUtil.RemoveDir("Output/EmbeddedObject");

	MemoryInit();
	ObjectsInit("Output/EmbeddedObject/");
	SetupEmbeddedObjectConstructors();

	Ptr<CRoot> pRoot = ORoot();
	Ptr<CEmbeddedComplex> pComplex = OMalloc(CEmbeddedComplex)->Init();
	oiComplex = pComplex->GetOI();

	Ptr<CEmbeddedContainer> pContainer = &pComplex->mcContainer;
	pRoot->Add(pContainer);

	bResult = gcObjects.Flush(TRUE, TRUE);
	AssertTrue(bResult);

	ObjectsKill();
	MemoryKill();

	AssertNull(&pContainer);

	MemoryInit();
	ObjectsInit("Output/EmbeddedObject/");
	SetupEmbeddedObjectConstructors();

	pRoot = gcObjects.GetRoot();
	AssertTrue(pRoot.IsNotNull());
	pContainer = pRoot->Get(0);
	AssertTrue(pContainer.IsHollow());
	AssertInt(0, pContainer.Object()->GetNumEmbedded());
	AssertLongLongInt(-1, pContainer.GetIndex());

	szClassName = pContainer->ClassName();
	AssertString("CEmbeddedContainer", szClassName);

	pComplex = pContainer->GetEmbeddingContainer();
	//Kinda feels like this test just stopped...

	ObjectsKill();
	MemoryKill();
}
コード例 #30
0
void TestDehollowficationFromChunkFileSource(void)
{
	CFileUtil		cFileUtil;

	cFileUtil.RemoveDir("Output\\Dehollowfication\\ChunkFile");

	MemoryInit();
	ObjectsInit("Output\\Dehollowfication\\Temp");
	WriteDehollowficationChunkedFile();
	ObjectsKill();
	MemoryKill();
	cFileUtil.RemoveDir("Output\\Dehollowfication\\Temp");

	CObjectSourceChunked* pcObjectSourceChunked;


	CDiskFile*	pcDiskFile = DiskFile("Output\\Dehollowfication\\ChunkFile\\Double.DRG");

	MemoryInit();
	ObjectsInit("Output\\Dehollowfication\\Temp");
	SetupDehollowficationConstructors();

	pcObjectSourceChunked = (CObjectSourceChunked*)gcObjects.AddSource<CObjectConverterNative>(pcDiskFile, "Double");  //Note the .DRG is intentionally dropped.
	AssertNotNull(pcObjectSourceChunked);

	AssertInt(4, pcObjectSourceChunked->NumNames());
	AssertString("Diamond End", pcObjectSourceChunked->GetName(0));
	AssertString("Double Start", pcObjectSourceChunked->GetName(1));
	AssertString("NamedString 1", pcObjectSourceChunked->GetName(2));
	AssertString("NamedString 2", pcObjectSourceChunked->GetName(3));

	Ptr<CTestDoubleNamedString> pStart;

	pStart = gcObjects.Get("Double Start");
	AssertTrue(pStart.IsNotNull());
	AssertString("CTestDoubleNamedString", pStart.ClassName());

	AssertTrue(pStart->mpSplit1.IsHollow());
	AssertTrue(pStart->mpSplit2.IsHollow());
	AssertFalse(pStart->mszString.IsHollow());

	pStart->mpSplit1->ClassName();
	AssertFalse(pStart->mpSplit1.IsHollow());
	AssertString("CTestNamedString", pStart->mpSplit1.ClassName());

	ObjectsKill();
	MemoryKill();
}