~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/lib/std/tst/ucd/t_cnfd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ---------------------------------------------------------------------------
2
 
// - t_cnfd.cpp                                                              -
3
 
// - unicode database (ucd) library - normal form decomposition (nfd) tester -
4
 
// ---------------------------------------------------------------------------
5
 
// - This program is free software;  you can redistribute it  and/or  modify -
6
 
// - it provided that this copyright notice is kept intact.                  -
7
 
// -                                                                         -
8
 
// - This program  is  distributed in  the hope  that it will be useful, but -
9
 
// - without  any  warranty;  without  even   the   implied    warranty   of -
10
 
// - merchantability or fitness for a particular purpose.  In no event shall -
11
 
// - the copyright holder be liable for any  direct, indirect, incidental or -
12
 
// - special damages arising in any way out of the use of this software.     -
13
 
// ---------------------------------------------------------------------------
14
 
// - copyright (c) 1999-2007 amaury darsch                                   -
15
 
// ---------------------------------------------------------------------------
16
 
 
17
 
#include "t_cnft.hxx"
18
 
 
19
 
namespace afnix {
20
 
  // this procedure returns true if a field is a single code point
21
 
  static bool nfd_is_single (const t_quad fld[NFT_ELM_MAX]) {
22
 
    if (fld[0] == nilq) return false;
23
 
    for (long i = 1; i < NFT_ELM_MAX; i++) {
24
 
      if (fld[i] != nilq) return false;
25
 
    }
26
 
    return true;
27
 
  }
28
 
 
29
 
  // this procedure compare 2 fields
30
 
  static bool nfd_cmp_fld (const t_quad dst[UCD_CDV_MAX], 
31
 
                           const t_quad fld[UCD_CDV_MAX]) {
32
 
    for (long i = 0; i < UCD_CDV_MAX; i++) {
33
 
      if (dst[i] != fld[i]) return false;
34
 
    }
35
 
    return true;
36
 
  }
37
 
 
38
 
  // this procedure test a nfd transformationd at index 0
39
 
  static bool nfd_test_0 (void) {
40
 
    // loop in the test data
41
 
    for (long i = 0; i < NFT_TEST_SIZE; i++) {
42
 
      // get the data sample
43
 
      const nft_t* data = &NFT_TEST_DATA[i];
44
 
      // check for single code point
45
 
      t_quad dst[UCD_CDV_MAX];
46
 
      if (nfd_is_single ((*data)[0]) == true) { 
47
 
        // get the code point and transform it
48
 
        t_quad code = (*data)[0][0];
49
 
        c_ucdnfd (dst, code);
50
 
        // compare two fields
51
 
        if (nfd_cmp_fld (dst, (*data)[2]) == false) {
52
 
          return false;
53
 
        }
54
 
      }
55
 
      // check for a full array
56
 
      c_ucdnfd (dst, (*data)[0]);
57
 
      // compare two fields
58
 
      if (nfd_cmp_fld (dst, (*data)[2]) == false) {
59
 
        return false;
60
 
      }
61
 
    }
62
 
    return true;
63
 
  }
64
 
}
65
 
 
66
 
int main (int, char**) {
67
 
  using namespace afnix;
68
 
 
69
 
  // check first the version consistency
70
 
  if (NFT_MAJOR != UCD_MAJOR) return 1;
71
 
  if (NFT_MINOR != UCD_MINOR) return 1;
72
 
  if (NFT_PATCH != UCD_PATCH) return 1;
73
 
  
74
 
  // check consistent UCD_CDV_MAX SIZE/NFT_ELM_MAX
75
 
  // this ensure that the array have the same size
76
 
  if (UCD_CDV_MAX != NFT_ELM_MAX) return 1;
77
 
 
78
 
  // test the single code point first
79
 
  if (nfd_test_0 () == false) return 1;
80
 
 
81
 
  // done
82
 
  return 0;
83
 
}