2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Added ntoh64 and hton64 as inline functions.
	* src/Util.cc
	* test/UtilTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-08-24 07:55:34 +00:00
parent ed25d2e245
commit 02dde388b8
3 changed files with 34 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added ntoh64 and hton64 as inline functions.
* src/Util.cc
* test/UtilTest.cc
2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added sqlite3 depenency and Firefox3 cookie support.

View File

@ -61,6 +61,19 @@ class FileEntry;
#define DIV_FLOOR(X,Y) ((X)/(Y)+((X)%(Y)? 1:0))
#ifdef WORDS_BIGENDIAN
inline uint64_t ntoh64(uint64_t x) { return x; }
inline uint64_t hton64(uint64_t x) { return x; }
#else // !WORDS_BIGENDIAN
inline uint64_t byteswap64(uint64_t x) {
uint64_t v1 = ntohl(x & 0x00000000ffffffff);
uint64_t v2 = ntohl(x >> 32);
return (v1 << 32)|v2;
}
inline uint64_t ntoh64(uint64_t x) { return byteswap64(x); }
inline uint64_t hton64(uint64_t x) { return byteswap64(x); }
#endif // !WORDS_BIGENDIAN
class Util {
public:
static void split(std::pair<std::string, std::string>& hp,

View File

@ -46,6 +46,7 @@ class UtilTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testItos);
CPPUNIT_TEST(testUitos);
CPPUNIT_TEST(testHttpGMT);
CPPUNIT_TEST(testNtoh64);
CPPUNIT_TEST_SUITE_END();
private:
@ -85,6 +86,7 @@ public:
void testItos();
void testUitos();
void testHttpGMT();
void testNtoh64();
};
@ -681,4 +683,17 @@ void UtilTest::testHttpGMT()
Util::httpGMT("Tue, 2008/10/10 23:33:33 UTC"));
}
void UtilTest::testNtoh64()
{
uint64_t x = 0xff00ff00ee00ee00LL;
#ifdef WORDS_BIGENDIAN
CPPUNIT_ASSERT_EQUAL(x, ntoh64(x));
CPPUNIT_ASSERT_EQUAL(x, hton64(x));
#else // !WORDS_BIGENDIAN
uint64_t y = 0x00ee00ee00ff00ffLL;
CPPUNIT_ASSERT_EQUAL(y, ntoh64(x));
CPPUNIT_ASSERT_EQUAL(x, hton64(y));
#endif // !WORDS_BIGENDIAN
}
} // namespace aria2