2009-04-16 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Rewritten array operation functions.
	* src/BitfieldMan.cc
	* src/array_fun.h
	* test/array_funTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2009-04-16 13:43:23 +00:00
parent e19447a54b
commit d2d4f67bbe
4 changed files with 196 additions and 224 deletions

View file

@ -1,13 +1,13 @@
#include "array_fun.h"
#include <cppunit/extensions/HelperMacros.h>
using namespace aria2::expr;
namespace aria2 {
class array_funTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(array_funTest);
CPPUNIT_TEST(testBit_negate);
CPPUNIT_TEST(testBit_and);
CPPUNIT_TEST(testArray_negate);
CPPUNIT_TEST(testArray_and);
CPPUNIT_TEST(testArrayLength);
@ -33,49 +33,31 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION(array_funTest);
void array_funTest::testBit_negate()
{
unsigned char b = 0xaa;
CPPUNIT_ASSERT_EQUAL((unsigned char)0x55, bit_negate<unsigned char>()(b));
}
void array_funTest::testBit_and()
{
unsigned char b = 0xaa;
CPPUNIT_ASSERT_EQUAL((unsigned char)0x0a, bit_and<unsigned char>()(b, 0x0a));
}
void array_funTest::testArray_negate()
{
unsigned char a[] = { 0xaa, 0x55 };
array_fun<unsigned char> f = array_negate((unsigned char*)a);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x55, f[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0xaa, f[1]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x55, (~arrayRef(a))[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0xaa, (~array((unsigned char*)a))[1]);
array_fun<unsigned char> ff = array_negate(f);
CPPUNIT_ASSERT_EQUAL((unsigned char)0xaa, ff[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x55, ff[1]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0xaa, (~~arrayRef(a))[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x55, (~~arrayRef(a))[1]);
}
void array_funTest::testArray_and()
{
unsigned char a1[] = { 0xaa, 0x55 };
unsigned char a2[] = { 0x1a, 0x25 };
array_fun<unsigned char> f = array_and((unsigned char*)a1, (unsigned char*)a2);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x0a, f[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x05, f[1]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x0a, (arrayRef(a1)&arrayRef(a2))[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x05, (arrayRef(a1)&arrayRef(a2))[1]);
array_fun<unsigned char> f2 = array_and((unsigned char*)a1, array_negate(a2));
CPPUNIT_ASSERT_EQUAL((unsigned char)0xa0, f2[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x50, f2[1]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0xa0, (arrayRef(a1)&~arrayRef(a2))[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x50, (arrayRef(a1)&~arrayRef(a2))[1]);
array_fun<unsigned char> f3 = array_and(array_negate(a2), (unsigned char*)a1);
CPPUNIT_ASSERT_EQUAL((unsigned char)0xa0, f3[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x50, f3[1]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0xa0, (~arrayRef(a2)&arrayRef(a1))[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x50, (~arrayRef(a2)&arrayRef(a1))[1]);
array_fun<unsigned char> f4 = array_and(array_negate(a1), array_negate(a2));
CPPUNIT_ASSERT_EQUAL((unsigned char)0x45, f4[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x8a, f4[1]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x45, (~arrayRef(a1)&~arrayRef(a2))[0]);
CPPUNIT_ASSERT_EQUAL((unsigned char)0x8a, (~arrayRef(a1)&~arrayRef(a2))[1]);
}
void array_funTest::testArrayLength()