File: Base32Test.cc

package info (click to toggle)
aria2 1.37.0%2Bdebian-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,128 kB
  • sloc: cpp: 115,006; ansic: 9,140; makefile: 1,466; ruby: 475; python: 373; sh: 260; xml: 176
file content (56 lines) | stat: -rw-r--r-- 1,784 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "base32.h"

#include <cppunit/extensions/HelperMacros.h>

#include "util.h"

namespace aria2 {

class Base32Test : public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE(Base32Test);
  CPPUNIT_TEST(testEncode);
  CPPUNIT_TEST(testDecode);
  CPPUNIT_TEST_SUITE_END();

public:
  void testEncode();
  void testDecode();
};

CPPUNIT_TEST_SUITE_REGISTRATION(Base32Test);

void Base32Test::testEncode()
{
  CPPUNIT_ASSERT_EQUAL(std::string(), base32::encode(""));
  CPPUNIT_ASSERT_EQUAL(std::string("GE======"), base32::encode("1"));
  CPPUNIT_ASSERT_EQUAL(std::string("GEZA===="), base32::encode("12"));
  CPPUNIT_ASSERT_EQUAL(std::string("GEZDG==="), base32::encode("123"));
  CPPUNIT_ASSERT_EQUAL(std::string("GEZDGNA="), base32::encode("1234"));
  CPPUNIT_ASSERT_EQUAL(std::string("GEZDGNBV"), base32::encode("12345"));
  std::string s = "248d0a1cd08284";
  CPPUNIT_ASSERT_EQUAL(std::string("ESGQUHGQQKCA===="),
                       base32::encode(util::fromHex(s.begin(), s.end())));
}

void Base32Test::testDecode()
{
  std::string s = "";
  CPPUNIT_ASSERT_EQUAL(std::string(), base32::decode(s.begin(), s.end()));
  s = "GE======";
  CPPUNIT_ASSERT_EQUAL(std::string("1"), base32::decode(s.begin(), s.end()));
  s = "GEZA====";
  CPPUNIT_ASSERT_EQUAL(std::string("12"), base32::decode(s.begin(), s.end()));
  s = "GEZDG===";
  CPPUNIT_ASSERT_EQUAL(std::string("123"), base32::decode(s.begin(), s.end()));
  s = "GEZDGNA=";
  CPPUNIT_ASSERT_EQUAL(std::string("1234"), base32::decode(s.begin(), s.end()));
  s = "GEZDGNBV";
  CPPUNIT_ASSERT_EQUAL(std::string("12345"),
                       base32::decode(s.begin(), s.end()));
  s = "gezdgnbv";
  CPPUNIT_ASSERT_EQUAL(std::string("12345"),
                       base32::decode(s.begin(), s.end()));
}

} // namespace aria2