File: encodingtest.cpp

package info (click to toggle)
tntnet 3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,488 kB
  • sloc: cpp: 16,636; javascript: 8,109; ansic: 2,189; makefile: 861; sh: 317; xml: 258; perl: 159; sql: 14
file content (57 lines) | stat: -rw-r--r-- 1,819 bytes parent folder | download
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
57
#include <cxxtools/unit/testsuite.h>
#include <cxxtools/unit/registertest.h>
#include <tnt/encoding.h>

class EncodingTest : public cxxtools::unit::TestSuite
{
  public:
    EncodingTest()
      : cxxtools::unit::TestSuite("encoding")
    {
      registerMethod("default", *this, &EncodingTest::def);
      registerMethod("whitespace", *this, &EncodingTest::whitespace);
      registerMethod("wildcard", *this, &EncodingTest::wildcard);
      registerMethod("parse", *this, &EncodingTest::parse);
      registerMethod("parseIdentity", *this, &EncodingTest::parseIdentity);
    }

    void def()
    {
        tnt::Encoding enc;
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("identity"), 1001);
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("gzip"), 0);
    }

    void whitespace()
    {
        tnt::Encoding enc(" blah ; q = 0.764 , * ; q \t = 0.67 ");
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("blah"), 764);
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("identity"), 670);
    }

    void wildcard()
    {
        tnt::Encoding enc("*;q=0.7");
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("identity"), 700);
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("gzip"), 700);
    }

    void parse()
    {
        tnt::Encoding enc("deflate, gzip;q=1.0, *;q=0.5");
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("deflate"), 1000);
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("gzip"), 1000);
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("blah"), 500);
    }

    void parseIdentity()
    {
        tnt::Encoding enc("identity;q=1, *;q=0");
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("identity"), 1000);
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("deflate"), 0);
        CXXTOOLS_UNIT_ASSERT_EQUALS(enc.accept("gzip"), 0);
    }

};

cxxtools::unit::RegisterTest<EncodingTest> register_EncodingTest;