mirror of
https://github.com/aria2/aria2.git
synced 2026-04-11 23:39:05 +00:00
Make a2netcompat.h include a2io.h to fix compilation error:
* src/a2netcompat.h
* src/SocketCore.cc: Removed include of a2io.h
* src/Util.cc: Removed include of a2io.h
Gather time related functions to a2time.h:
* src/a2time.h: New file.
* src/DefaultPeerStorage.cc
* src/SimpleLogger.cc
* src/Util.{h, cc}
* src/SimpleRandomizer.h
* src/TimeA2.{h,cc}
* src/DownloadCommand.cc
* src/main.cc
Removed #ifdef __MINGW32__ since gai_strerror is included in
a2netcompat.h:
* src/NameResolver.cc
Fixed compilation error without openssl:
* src/SocketCore.{h,cc}: Moved include of openssl/err.h to
SocketCore.h
Added default block to suppress compiler warnings:
* src/MetalinkRequestInfo.cc (AccumulateNonP2PUrl::operator())
2007-07-26 Ross Smith II <aria2spam at smithii dot com>
MinGW build enhancements. The following files are added:
* src/gai_strerror.{c,h}
* src/gettimeofday.{c,h}
Changes to support the above new files:
* configure.ac
* src/Makefile.am
* src/a2netcompat.h
* src/TimeA2.cc
* src/DefaultPeerStorage.cc
* src/NameResolver.cc: removed mingw_strerror() function.
* src/SocketCore.cc: removed mingw_strerror() function.
Miscellaneous MinGW build fixes.
* src/a2io.h: Use _lseeki64() instead of lseek()
* src/common.h
* src/DefaultFileAllocator.cc
* src/GlowFileAllocator.cc
* src/main.cc: Moved #include "prefs.h" to quiet compile error.
* src/NameResolver.cc
(callback): Changed int32_t to int.
(resolve): Changed int32_t to int.
* src/Platform.cc
* src/Platform.h
* test/MultiDiskWriterTest.cc
* test/PeerMessageUtilTest.cc
* src/localtime_r.c: Add DeleteCriticalSection() and at exit().
Other enhancements and fixes.
* src/HttpRequestCommand.cc
(executeInternal) Use non-blocking socket for HTTPS (MinGW
only).
* src/SocketCore.cc:
(error): New function to abstract errno/WSAGetLastError().
(errorMsg): New function to abstract errno/WSAGetLastError().
(initiateSecureConnection): Added more detailed error reporting.
* src/SocketCore.h: Added private variable blocking, to allow
proper handling of OpenSSL psuedo-errors.
* src/message.h
(EX_SSL_INIT_FAILURE)
(EX_SSL_IO_ERROR)
(EX_SSL_PROTOCOL_ERROR)
(EX_SSL_UNKNOWN_ERROR)
(EX_SSL_CONNECT_ERROR)
(EX_SOCKET_BLOCKING)
(EX_SOCKET_NONBLOCKING)
(EX_SOCKET_UNKNOWN_ERROR)
* src/Util.cc
(setGlobalSignalHandler): Renamed signal to sig as signal is a
reserved name.
(httpGMT): Fixed typo.
145 lines
3.9 KiB
C++
145 lines
3.9 KiB
C++
#include "common.h"
|
|
#include "MultiDiskWriter.h"
|
|
#include "a2io.h"
|
|
#include <string>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
using namespace std;
|
|
|
|
class MultiDiskWriterTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(MultiDiskWriterTest);
|
|
CPPUNIT_TEST(testWriteData);
|
|
CPPUNIT_TEST(testReadData);
|
|
CPPUNIT_TEST(testMessageDigest);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
private:
|
|
|
|
public:
|
|
void setUp() {
|
|
}
|
|
|
|
void testWriteData();
|
|
void testReadData();
|
|
void testMessageDigest();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MultiDiskWriterTest );
|
|
|
|
FileEntries createEntries() {
|
|
FileEntryHandle entry1(new FileEntry("file1.txt", 15, 0));
|
|
FileEntryHandle entry2(new FileEntry("file2.txt", 7, 15));
|
|
FileEntryHandle entry3(new FileEntry("file3.txt", 3, 22));
|
|
unlink("file1.txt");
|
|
unlink("file2.txt");
|
|
unlink("file3.txt");
|
|
FileEntries entries;
|
|
entries.push_back(entry1);
|
|
entries.push_back(entry2);
|
|
entries.push_back(entry3);
|
|
return entries;
|
|
}
|
|
|
|
void readFile(const string& filename, char* buf, int bufLength) {
|
|
FILE* f = fopen(filename.c_str(), "r");
|
|
if(f == NULL) {
|
|
abort();
|
|
}
|
|
int retval = fread(buf, bufLength, 1, f);
|
|
fclose(f);
|
|
if(retval != 1) {
|
|
abort();
|
|
}
|
|
}
|
|
|
|
void MultiDiskWriterTest::testWriteData() {
|
|
MultiDiskWriter dw(2);
|
|
dw.setFileEntries(createEntries());
|
|
|
|
dw.openFile(".");
|
|
string msg = "12345";
|
|
dw.writeData(msg.c_str(), msg.size(), 0);
|
|
dw.closeFile();
|
|
|
|
char buf[128];
|
|
readFile("file1.txt", buf, 5);
|
|
buf[5] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(msg, string(buf));
|
|
|
|
dw.openFile(".");
|
|
string msg2 = "67890ABCDEF";
|
|
dw.writeData(msg2.c_str(), msg2.size(), 5);
|
|
dw.closeFile();
|
|
|
|
readFile("file1.txt", buf, 15);
|
|
buf[15] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("1234567890ABCDE"), string(buf));
|
|
readFile("file2.txt", buf, 1);
|
|
buf[1] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("F"), string(buf));
|
|
|
|
dw.openFile(".");
|
|
string msg3 = "12345123456712";
|
|
dw.writeData(msg3.c_str(), msg3.size(), 10);
|
|
dw.closeFile();
|
|
|
|
readFile("file1.txt", buf, 15);
|
|
buf[15] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("123456789012345"), string(buf));
|
|
readFile("file2.txt", buf, 7);
|
|
buf[7] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("1234567"), string(buf));
|
|
readFile("file3.txt", buf, 2);
|
|
buf[2] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("12"), string(buf));
|
|
}
|
|
|
|
void MultiDiskWriterTest::testReadData() {
|
|
FileEntryHandle entry1(new FileEntry("file1r.txt", 15, 0));
|
|
FileEntryHandle entry2(new FileEntry("file2r.txt", 7, 15));
|
|
FileEntryHandle entry3(new FileEntry("file3r.txt", 3, 22));
|
|
FileEntries entries;
|
|
entries.push_back(entry1);
|
|
entries.push_back(entry2);
|
|
entries.push_back(entry3);
|
|
MultiDiskWriter dw(2);
|
|
dw.setFileEntries(entries);
|
|
|
|
dw.openFile(".");
|
|
char buf[128];
|
|
dw.readData(buf, 15, 0);
|
|
buf[15] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("1234567890ABCDE"), string(buf));
|
|
dw.readData(buf, 10, 6);
|
|
buf[10] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("7890ABCDEF"), string(buf));
|
|
dw.readData(buf, 4, 20);
|
|
buf[4] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("KLMN"), string(buf));
|
|
dw.readData(buf, 25, 0);
|
|
buf[25] = '\0';
|
|
CPPUNIT_ASSERT_EQUAL(string("1234567890ABCDEFGHIJKLMNO"), string(buf));
|
|
}
|
|
|
|
void MultiDiskWriterTest::testMessageDigest() {
|
|
FileEntryHandle entry1(new FileEntry("file1r.txt", 15, 0));
|
|
FileEntryHandle entry2(new FileEntry("file2r.txt", 7, 15));
|
|
FileEntryHandle entry3(new FileEntry("file3r.txt", 3, 22));
|
|
FileEntries entries;
|
|
entries.push_back(entry1);
|
|
entries.push_back(entry2);
|
|
entries.push_back(entry3);
|
|
MultiDiskWriter dw(2);
|
|
dw.setFileEntries(entries);
|
|
|
|
dw.openFile(".");
|
|
string sha1sum = dw.messageDigest(0, 25, DIGEST_ALGO_SHA1);
|
|
CPPUNIT_ASSERT_EQUAL(string("76495faf71ca63df66dce99547d2c58da7266d9e"), sha1sum);
|
|
sha1sum = dw.messageDigest(15, 7, DIGEST_ALGO_SHA1);
|
|
CPPUNIT_ASSERT_EQUAL(string("737660d816fb23c2d5bc74f62d9b01b852b2aaca"), sha1sum);
|
|
sha1sum = dw.messageDigest(10, 14, DIGEST_ALGO_SHA1);
|
|
CPPUNIT_ASSERT_EQUAL(string("6238bf61dd8df8f77156b2378e9e39cd3939680c"), sha1sum);
|
|
dw.closeFile();
|
|
}
|