1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #include <stdio.h>
8 : #include <stdlib.h>
9 : #include <string.h>
10 :
11 : #include <string>
12 :
13 : #include "native_client/src/trusted/debug_stub/util.h"
14 :
15 : using std::string;
16 : using gdb_rsp::NibbleToInt;
17 : using gdb_rsp::IntToNibble;
18 : using gdb_rsp::stringvec;
19 :
20 :
21 1 : int TestUtil() {
22 1 : char goodStr[] = "0123456789abcdefABCDEF";
23 : int good;
24 : int val;
25 : int a;
26 1 : int errCnt = 0;
27 :
28 : // Make sure we find expected and only expected conversions (0-9,a-f,A-F)
29 1 : good = 0;
30 1 : for (a = 0; a < 256; a++) {
31 : // NOTE: Exclude 'zero' since the terminator is found by strchr
32 1 : bool found = a && (strrchr(goodStr, a) != NULL);
33 1 : bool xvert = NibbleToInt(static_cast<char>(a), &val);
34 1 : if (xvert != found) {
35 : printf("FAILED NibbleToInt of '%c'(#%d), convertion %s.\n",
36 0 : a, a, xvert ? "succeeded" : "failed");
37 0 : errCnt++;
38 : }
39 1 : }
40 :
41 1 : good = 0;
42 1 : for (a = -256; a < 256; a++) {
43 : char ch;
44 1 : bool xvert = IntToNibble(a, &ch);
45 :
46 1 : if (xvert) {
47 1 : good++;
48 1 : if (!NibbleToInt(ch, &val)) {
49 0 : printf("FAILED IntToNibble on good NibbleToInt of #%d\n.\n", a);
50 0 : errCnt++;
51 : }
52 : // NOTE: check if IntToNible matches NibbleToInt looking at both
53 : // possitive and negative values of -15 to +15
54 1 : if (val != a) {
55 0 : printf("FAILED IntToNibble != NibbleToInt of #%d\n.\n", a);
56 0 : errCnt++;
57 : }
58 : }
59 1 : }
60 :
61 : // Although we check -15 to +15 above, we realy only want -7 to +15
62 : // to verify unsiged (0-15) plus signed (-7 to -1).
63 1 : if (good != 16) {
64 0 : printf("FAILED IntToNibble range of 0 to 15.\n");
65 0 : errCnt++;
66 : }
67 :
68 1 : string xml = "qXfer:features:read:target.xml:0,7ca";
69 1 : string str;
70 1 : stringvec vec, vec2;
71 :
72 1 : return errCnt;
73 1 : }
74 :
|