MMapFile test
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3693 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
32dfb7e181
commit
779e0354d2
2 changed files with 61 additions and 0 deletions
|
@ -93,6 +93,10 @@ SOURCE=.\endian.cpp
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mmap.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\textrunner.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
|
|
57
Source/Tests/mmap.cpp
Normal file
57
Source/Tests/mmap.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include "../strlist.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int MMapFile::m_iAllocationGranularity = 0;
|
||||
int g_display_errors = 1;
|
||||
FILE *g_output = stderr;
|
||||
|
||||
void quit() {
|
||||
fprintf(g_output, "MMap quit\n");
|
||||
}
|
||||
|
||||
class MMapTest : public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE( MMapTest );
|
||||
CPPUNIT_TEST( testMMapFile );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void testMMapFile() {
|
||||
const int BUF_SIZE = 50000; // 50MB
|
||||
|
||||
MMapFile mmap;
|
||||
mmap.resize(BUF_SIZE);
|
||||
CPPUNIT_ASSERT_EQUAL( BUF_SIZE, mmap.getsize() );
|
||||
|
||||
void *buf = mmap.get(0, BUF_SIZE);
|
||||
memset(buf, 0x85, BUF_SIZE);
|
||||
mmap.release();
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int offset1 = rand() % BUF_SIZE;
|
||||
int size1 = rand() % (BUF_SIZE - offset1);
|
||||
char *p1 = (char *) mmap.get(offset1, size1);
|
||||
|
||||
int offset2 = rand() % BUF_SIZE;
|
||||
int size2 = rand() % (BUF_SIZE - offset2);
|
||||
char *p2 = (char *) mmap.getmore(offset2, &size2);
|
||||
|
||||
int minsize = min(size1, size2);
|
||||
for (int j = 0; j < minsize; j++) {
|
||||
CPPUNIT_ASSERT_EQUAL( p1[j], p2[j] );
|
||||
}
|
||||
|
||||
mmap.release();
|
||||
mmap.release(p2, size2);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( MMapTest );
|
Loading…
Add table
Add a link
Reference in a new issue