示例#1
0
		std::vector<std::string>* generateNames(int number) {
			// this will avoid overriding previously generated names and keep consistent the results
				FileInputStream* fisNames = new FileInputStream("names.csv", "r");
				const char* fullNames = fisNames->readFull();
				FileInputStream* fisLastNames = new FileInputStream("last.csv", "r");
				const char* fullLast = fisLastNames->readFull();

				std::vector<std::string> names = split(fullNames, "\r");
				cout << names.size() << endl;
				std::vector<std::string> lastNames = split(fullLast, "\r");
				cout << lastNames.size() << endl;

				std::vector<std::string>* generated = new std::vector<std::string>();
				for (int x = 0; x < number; x++) {
					int i = rand() % names.size();
					std::string name = names.at(i);

					i = rand() % lastNames.size();
					std::string lastName = lastNames.at(i);

					std::string fullName = name + " " + lastName;

					generated->push_back(fullName);
				}

				fisNames->close();
				fisLastNames->close();

				delete fisNames;
				delete fisLastNames;
				return generated;
		}
示例#2
0
TEST(testIndexP, generateNames) {
	// this will avoid overriding previously generated names and keep consistent the results
	if (!existFile("names.txt")) {
		FileInputStream* fisNames = new FileInputStream("names.csv", "r");
		const char* fullNames = fisNames->readFull();
		FileInputStream* fisLastNames = new FileInputStream("last.csv", "r");
		const char* fullLast = fisLastNames->readFull();

		std::vector<string> names = split(fullNames, "\r");
		cout << names.size() << endl;
		std::vector<string> lastNames = split(fullLast, "\r");
		cout << lastNames.size() << endl;

		FileOutputStream* fos = new FileOutputStream("names.txt", "w+");
		for (int x = 0; x < 10000000; x++) {
			int i = rand() % names.size();
			std::string name = names.at(i);

			i = rand() % lastNames.size();
			std::string lastName = lastNames.at(i);

			std::string fullName = name + " " + lastName;

			fos->writeString(fullName);
		}

		fos->close();
		fisNames->close();
		fisLastNames->close();

		delete fos;
		delete fisNames;
		delete fisLastNames;
	}
}
void CImageLabel::LoadImage(const char * pImageName)
{
	if ( m_pTGA )
		delete m_pTGA;

	// Load the Image
	m_pTGA = LoadTGAForRes(pImageName);

	if ( m_pTGA == NULL )
	{
		// we didn't find a matching image file for this resolution
		// try to load file resolution independent

		char sz[256];
		sprintf(sz, "%s/%s",gEngfuncs.pfnGetGameDirectory(), pImageName );
		FileInputStream* fis = new FileInputStream( sz, false );
		m_pTGA = new BitmapTGA(fis,true);
		fis->close();
	}

	if ( m_pTGA == NULL )
		return;	// unable to load image
	 	
	int w,t;

	m_pTGA->getSize( w, t );

	setSize( XRES (w),YRES (t) );
	setImage( m_pTGA );
}
示例#4
0
TEST(TestCommand, testShownamespacesCommand) {
	cout << "testShownamespacesCommand" << endl;
	FileOutputStream* fos = new FileOutputStream("test.dat", "wb");

	CommandWriter* writer = new CommandWriter(fos);
	ShownamespacesCommand cmd;
	cmd.setDB("testdb");
	writer->writeCommand(&cmd);

	fos->close();
	delete fos;
	delete writer;

	FileInputStream* fis = new FileInputStream("test.dat", "rb");
	CommandReader* reader = new CommandReader(fis);

	Command* resCmd = reader->readCommand();
	EXPECT_TRUE(resCmd->commandType() == SHOWNAMESPACES);
	ShownamespacesCommand* sw = (ShownamespacesCommand*)resCmd;
	EXPECT_TRUE(sw->DB()->compare("testdb") == 0);

	fis->close();

	delete resCmd;
	delete fis;
	delete reader;
}
示例#5
0
// protected
void 
FileInputStreamTestCase::read (void)
{
	FileInputStream fin (TEST_FILE_NAME);
	
	int byte = fin.read ();
	CPPUNIT_ASSERT ( (char)byte == 'T');
	byte = fin.read ();
	CPPUNIT_ASSERT ((char)byte == 'e');
	
	unsigned char readBuf[11];
	CPPUNIT_ASSERT (fin.read(readBuf, 10) == 10);
	readBuf[10] = 0;
	CPPUNIT_ASSERT (strncmp ((char*) readBuf, "st line 1\r", 10) == 0);
	
	CPPUNIT_ASSERT (fin.read(readBuf, 4) == 4);
	CPPUNIT_ASSERT (strncmp ((char*) readBuf, "\nTes", 4) == 0);
	
	CPPUNIT_ASSERT_THROW (fin.read (0, 0), Exception);
	
	CPPUNIT_ASSERT ((char)fin.read () == 't');
	CPPUNIT_ASSERT (fin.read(readBuf, 0) == 0);
	CPPUNIT_ASSERT (fin.read(readBuf, 10) == 10);
	CPPUNIT_ASSERT (fin.read(readBuf, 4) == 4);
	CPPUNIT_ASSERT (fin.read(readBuf, 10) == 6);
	CPPUNIT_ASSERT (fin.read(readBuf, 4) == -1);
	CPPUNIT_ASSERT (fin.read() == -1);

	fin.close ();
}
示例#6
0
HRESULT CFileHelper::ReadAllText(LPCTSTR path, String & text)
{
	FileInputStream ifs;

	ifs.imbue(locale("chs"));

	ifs.open(path,ifs.in);

	if(!ifs.is_open()) return E_FAIL;

	ifs.seekg(0,ifs.end);

	int size=ifs.tellg();

	ifs.seekg(0);	

	TCHAR * s=(TCHAR *)malloc(sizeof(TCHAR) * (size+1));

	memset(s,0,sizeof(TCHAR)*(size+1));

	ifs._Read_s(s,size ,sizeof(TCHAR) * size);

	ifs.close();

	text = s;

	free(s);

	return S_OK;
}
示例#7
0
// protected
void 
FileInputStreamTestCase::getFileName (void)
{
	FileInputStream fin (TEST_FILE_NAME);
	CPPUNIT_ASSERT (fin.getFileName () == String (TEST_FILE_NAME));
	
	fin.close ();
}
示例#8
0
// protected
void 
FileInputStreamTestCase::close (void)
{
	FileInputStream fin (TEST_FILE_NAME);
	CPPUNIT_ASSERT ((char)fin.read () == 'T');
	fin.close ();	

}
示例#9
0
//-----------------------------------------------------------------------------
// Purpose: Loads a .tga file and returns a pointer to the VGUI tga object
//-----------------------------------------------------------------------------
BitmapTGA *LoadTGA( const char* pImageName )
{
	BitmapTGA	*pTGA;

	char sz[256];
	sprintf(sz, "%%d_%s", pImageName);

	// Load the Image
	FileInputStream* fis = new FileInputStream( GetVGUITGAName(sz), false );
	pTGA = new BitmapTGA(fis,true);
	fis->close();

	return pTGA;
}
示例#10
0
// protected
void 
FileInputStreamTestCase::ctors (void)
{	
	FileInputStream fin (TEST_FILE_NAME);
	
	File file (TEST_FILE_NAME);
	
	FileInputStream fin2(TEST_FILE_NAME, READ_SHARE);
	CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, WRITE_SHARE), Exception);
	fin2.close ();
	fin.close ();
	
	FileInputStream fin3(TEST_FILE_NAME, NONE_SHARE);
	CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, READ_SHARE), Exception);
	
}
示例#11
0
// protected
void 
FileInputStreamTestCase::available (void)
{
	FileInputStream fin (TEST_FILE_NAME);
	
	CPPUNIT_ASSERT (fin.available () == 37);
	fin.read ();
	CPPUNIT_ASSERT (fin.available () == 36);
	fin.read ();
	CPPUNIT_ASSERT (fin.available () == 35);
	
	unsigned char readBuf[4];
	fin.read(readBuf, 4);
	CPPUNIT_ASSERT (fin.available () == 31);
	
	fin.read(readBuf, 2);
	CPPUNIT_ASSERT (fin.available () == 29);
	
	fin.close ();	
}
示例#12
0
// protected
void 
FileInputStreamTestCase::seek (void)
{
	FileInputStream fin (TEST_FILE_NAME);	
	
	CPPUNIT_ASSERT_THROW (fin.seek (-1, BEGIN_ORIGIN), Exception);
	CPPUNIT_ASSERT (fin.seek (3, BEGIN_ORIGIN) == 3);
	CPPUNIT_ASSERT (fin.seek (21, BEGIN_ORIGIN) == 21);	
	CPPUNIT_ASSERT (fin.seek (38, BEGIN_ORIGIN) == 38);
	
	CPPUNIT_ASSERT (fin.seek (-7, CURRENT_ORIGIN) == 31);
	CPPUNIT_ASSERT (fin.seek (2, CURRENT_ORIGIN) == 33);
	CPPUNIT_ASSERT_THROW (fin.seek (-73, CURRENT_ORIGIN), Exception);
	CPPUNIT_ASSERT (fin.seek (24, CURRENT_ORIGIN) == 57);
	CPPUNIT_ASSERT (fin.seek (24, CURRENT_ORIGIN) == 81);
	
	CPPUNIT_ASSERT_THROW (fin.seek (-46, END_ORIGIN), Exception);
	CPPUNIT_ASSERT (fin.seek (-2, END_ORIGIN) == 35);	
	CPPUNIT_ASSERT (fin.seek (4, END_ORIGIN) == 41);
		
	fin.close ();

}
示例#13
0
TEST(TestCommand, testShowdbs) {
	cout << "testShowdbs" << endl;
	FileOutputStream* fos = new FileOutputStream("test.dat", "wb");

	CommandWriter* writer = new CommandWriter(fos);
	ShowdbsCommand cmd;
	writer->writeCommand(&cmd);

	fos->close();
	delete fos;
	delete writer;

	FileInputStream* fis = new FileInputStream("test.dat", "rb");
	CommandReader* reader = new CommandReader(fis);

	Command* resCmd = reader->readCommand();
	EXPECT_TRUE(resCmd->commandType() == SHOWDBS);

	fis->close();

	delete resCmd;
	delete fis;
	delete reader;
}