File: testlog.h

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (81 lines) | stat: -rw-r--r-- 2,837 bytes parent folder | download | duplicates (14)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
 * COPYRIGHT: 
 * Copyright (c) 2004-2010, International Business Machines Corporation and
 * others. All Rights Reserved.
 ********************************************************************/

/* Created by grhoten 03/17/2004 */

/* Base class for data driven tests */

#ifndef U_TESTFW_TESTLOG
#define U_TESTFW_TESTLOG

#include <string>
#include <string_view>
#include "unicode/utypes.h"
#include "unicode/testtype.h"

/** Facilitates internal logging of data driven test service 
 *  It would be interesting to develop this into a full      
 *  fledged control system as in Java.                       
 */
class T_CTEST_EXPORT_API TestLog {
public:
    virtual ~TestLog();
    virtual void errln(std::u16string_view message) = 0;
    virtual void logln(std::u16string_view message) = 0;
    virtual void dataerrln(std::u16string_view message) = 0;
    virtual const char* getTestDataPath(UErrorCode& err) = 0;
};

// Note: The IcuTestErrorCode used to be a subclass of ErrorCode, but that made it not usable for
// unit tests that work without U_SHOW_CPLUSPLUS_API.
// So instead we *copy* the ErrorCode API.

class T_CTEST_EXPORT_API IcuTestErrorCode {
public:
    IcuTestErrorCode(const IcuTestErrorCode&) = delete;
    IcuTestErrorCode& operator=(const IcuTestErrorCode&) = delete;

    IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName);
    virtual ~IcuTestErrorCode();

    // ErrorCode API
    operator UErrorCode & () { return errorCode; }
    operator UErrorCode * () { return &errorCode; }
    UBool isSuccess() const { return U_SUCCESS(errorCode); }
    UBool isFailure() const { return U_FAILURE(errorCode); }
    UErrorCode get() const { return errorCode; }
    void set(UErrorCode value) { errorCode=value; }
    UErrorCode reset();
    void assertSuccess() const;
    const char* errorName() const;

    // Returns true if isFailure().
    UBool errIfFailureAndReset();
    UBool errIfFailureAndReset(const char *fmt, ...);
    UBool errDataIfFailureAndReset();
    UBool errDataIfFailureAndReset(const char *fmt, ...);
    UBool expectErrorAndReset(UErrorCode expectedError);
    UBool expectErrorAndReset(UErrorCode expectedError, const char *fmt, ...);

    /** Sets an additional message string to be appended to failure output. */
    void setScope(const char* message);
    void setScope(std::u16string_view message);

protected:
    virtual void handleFailure() const;

private:
    UErrorCode errorCode;
    TestLog &testClass;
    const char *const testName;
    std::u16string scopeMessage;

    void errlog(UBool dataErr, std::u16string_view mainMessage, const char* extraMessage) const;
};

#endif