NSIS/Source/Tests/mmap.cpp
wizou 752d7d239a Jim Park's Unicode NSIS merging - Step 1 : switch to TCHARs where relevant.
Compiler output is identical before & after this step

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/branches/wizou@6036 212acab6-be3b-0410-9dea-997c60f758d6
2010-03-24 17:22:56 +00:00

76 lines
1.5 KiB
C++

// Unicode support by Jim Park -- 08/13/2007
//
#include <cppunit/extensions/HelperMacros.h>
#include "../mmap.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std; // for std::min
int g_display_errors = 1;
FILE *g_output = stderr;
void quit() {
_ftprintf(g_output, _T("MMap quit\n"));
}
class MMapTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE( MMapTest );
CPPUNIT_TEST( testMMapFile );
CPPUNIT_TEST_SUITE_END();
public:
void testMMapFile() {
size_t i;
const int BUF_SIZE = 50000; // 50MB
// resize
MMapFile mmap;
mmap.resize(BUF_SIZE);
CPPUNIT_ASSERT_EQUAL( BUF_SIZE, mmap.getsize() );
// set content
char *buf = (char *) mmap.get(0, BUF_SIZE);
for (i = 0; i < BUF_SIZE; i++) {
buf[i] = i % 256;
}
mmap.release();
// test content and get(), getmore()
srand(time(NULL));
for (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 j;
for (j = 0; j < size1; j++) {
CPPUNIT_ASSERT_EQUAL( p1[j], char((offset1 + j) % 256) );
}
for (j = 0; j < size2; j++) {
CPPUNIT_ASSERT_EQUAL( p2[j], char((offset2 + j) % 256) );
}
mmap.release();
mmap.release(p2, size2);
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION( MMapTest );