vocabtest.cpp

来自「一个语言识别引擎」· C++ 代码 · 共 53 行

CPP
53
字号
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

/*
 * Copyright (C) 2006 Paul Fitzpatrick
 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
 *
 */


#include <yarp/String.h>
#include <yarp/os/Vocab.h>

#include "TestList.h"

using namespace yarp::os;
using namespace yarp;

class VocabTest : public UnitTest {
public:
    virtual String getName() { return "VocabTest"; }

    void checkConvert() {
        report(0,"checking vocabulary conversions");
        checkEqual(VOCAB2('h','i'),Vocab::encode("hi"),"encoding");
        checkEqual(Vocab::decode(Vocab::encode("hi")).c_str(),"hi","decoding");
        checkEqual(VOCAB4('h','i','g','h'),Vocab::encode("high"),"encoding");
        checkEqual(Vocab::decode(Vocab::encode("high")).c_str(),"high","decoding");
        report(0,"checking compile-time functions");
        NetInt32 code = Vocab::encode("stop");
        switch(code) {
        case VOCAB3('s','e','t'):
            report(1,"very strange error switching");
            break;
        case VOCAB4('s','t','o','p'):
            report(0,"good switch");
            break;
        default:
            report(1,"error switching");
            break;
        }
    }

    virtual void runTests() {
        checkConvert();
    }
};

static VocabTest theVocabTest;

UnitTest& getVocabTest() {
    return theVocabTest;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?