tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testlog.h (2837B)


      1 // © 2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /********************************************************************
      4 * COPYRIGHT: 
      5 * Copyright (c) 2004-2010, International Business Machines Corporation and
      6 * others. All Rights Reserved.
      7 ********************************************************************/
      8 
      9 /* Created by grhoten 03/17/2004 */
     10 
     11 /* Base class for data driven tests */
     12 
     13 #ifndef U_TESTFW_TESTLOG
     14 #define U_TESTFW_TESTLOG
     15 
     16 #include <string>
     17 #include <string_view>
     18 #include "unicode/utypes.h"
     19 #include "unicode/testtype.h"
     20 
     21 /** Facilitates internal logging of data driven test service 
     22 *  It would be interesting to develop this into a full      
     23 *  fledged control system as in Java.                       
     24 */
     25 class T_CTEST_EXPORT_API TestLog {
     26 public:
     27    virtual ~TestLog();
     28    virtual void errln(std::u16string_view message) = 0;
     29    virtual void logln(std::u16string_view message) = 0;
     30    virtual void dataerrln(std::u16string_view message) = 0;
     31    virtual const char* getTestDataPath(UErrorCode& err) = 0;
     32 };
     33 
     34 // Note: The IcuTestErrorCode used to be a subclass of ErrorCode, but that made it not usable for
     35 // unit tests that work without U_SHOW_CPLUSPLUS_API.
     36 // So instead we *copy* the ErrorCode API.
     37 
     38 class T_CTEST_EXPORT_API IcuTestErrorCode {
     39 public:
     40    IcuTestErrorCode(const IcuTestErrorCode&) = delete;
     41    IcuTestErrorCode& operator=(const IcuTestErrorCode&) = delete;
     42 
     43    IcuTestErrorCode(TestLog &callingTestClass, const char *callingTestName);
     44    virtual ~IcuTestErrorCode();
     45 
     46    // ErrorCode API
     47    operator UErrorCode & () { return errorCode; }
     48    operator UErrorCode * () { return &errorCode; }
     49    UBool isSuccess() const { return U_SUCCESS(errorCode); }
     50    UBool isFailure() const { return U_FAILURE(errorCode); }
     51    UErrorCode get() const { return errorCode; }
     52    void set(UErrorCode value) { errorCode=value; }
     53    UErrorCode reset();
     54    void assertSuccess() const;
     55    const char* errorName() const;
     56 
     57    // Returns true if isFailure().
     58    UBool errIfFailureAndReset();
     59    UBool errIfFailureAndReset(const char *fmt, ...);
     60    UBool errDataIfFailureAndReset();
     61    UBool errDataIfFailureAndReset(const char *fmt, ...);
     62    UBool expectErrorAndReset(UErrorCode expectedError);
     63    UBool expectErrorAndReset(UErrorCode expectedError, const char *fmt, ...);
     64 
     65    /** Sets an additional message string to be appended to failure output. */
     66    void setScope(const char* message);
     67    void setScope(std::u16string_view message);
     68 
     69 protected:
     70    virtual void handleFailure() const;
     71 
     72 private:
     73    UErrorCode errorCode;
     74    TestLog &testClass;
     75    const char *const testName;
     76    std::u16string scopeMessage;
     77 
     78    void errlog(UBool dataErr, std::u16string_view mainMessage, const char* extraMessage) const;
     79 };
     80 
     81 #endif