??????????????????????????????????????????????ù????д?????????????????????д???????????????????????????????????????
????1??????????????????????????λ?????????????????????MyString??????????????????????????????
//????
#ifndef MYSTRING_H
#define MYSTRING_H
#include <QString>
class CGMyString
{
public:
QString subQString(int start?? int end);
public:
CGMyString(QString& qstr);
};
#endif // MYSTRING_H
//??????#include "MyString.h"
CGMyString::CGMyString(QString &qstr)
{
}
QString CGMyString::subQString(int start?? int end)
{
QString re;
return re;
}
????2?????д???????
#include <QString>
#include <QtTest>
#include <MyString.h>
class MyStringTest : public QObject
{
Q_OBJECT
public:
MyStringTest();
private Q_SLOTS:
void testSubQString();
void testSubQString_data();
};
MyStringTest::MyStringTest()
{
}
void MyStringTest::testSubQString()
{
QFETCH(QString?? str);
QFETCH(int?? start);
QFETCH(int?? end);
QFETCH(QString?? result);
CGMyString testStr(str);
QString execResult = testStr.subQString(start?? end);
QVERIFY2(0 == result.compare(execResult)?? "MyStringTest_subQString");
}
void MyStringTest::testSubQString_data()
{
QTest::addColumn<QString>("str");
QTest::addColumn<int>("start");
QTest::addColumn<int>("end");
QTest::addColumn<QString>("result");
QTest::newRow("illegal start") << QString::fromLocal8Bit("HELLO") << -1 << 2 << "";
QTest::newRow("illegal end") << QString::fromLocal8Bit("HELLO") << 0 << 7 << "";
QTest::newRow("legal") << QString::fromLocal8Bit("HELLO") << 0 << 3 << "HELL";
}
QTEST_APPLESS_MAIN(MyStringTest)
#include "tst_unittesttest.moc"