Android Automotive的Qt测试

Tests in Qt for Android Automotive

Android Automotive的Qt测试

Wednesday June 15, 2022 by Ramon Sadornil Rivera | Comments

​2022年6月15日星期三Ramon Sadornil Rivera评论

Qt IF Android Vehicle Properties is a Qt for Android Automotive (QtAA) submodule that provides a C++ and QML wrapper for the Android Automotive Vehicle Properties. The Qt Interface Framework (QtIF) is used to generate the code and avoid maintaining duplicate code per each vehicle property.

Qt IF Android Vehicle Properties是一个Qt for Android Automotive(QtAA)子模块,它为Android Automotive Vehicle属性提供了C++和QML包装。Qt接口框架(QtIF)用于生成代码,避免每个属性维护重复代码。

Like in other Qt solutions, Qt for Android Automotive contains tests. QtAA implements some of those tests standardly, using the Qt Test framework. On the other hand, the Qt IF Android Vehicle Properties tests depend on QtIFWe want to share how you can leverage QtIF to quickly create and maintain your tests.

​与其他Qt解决方案一样,Android Automotive的Qt包含测试。QtAA使用Qt测试框架标准地实现其中一些测试。另一方面,Qt IF Android车辆性能测试取决于QtIF。我们希望与您分享如何利用QtIF快速创建和维护测试。

QtIF "test" TEMPLATE

QtIF“测试”模板

QtIF delivers its test Template. The generated tests are an excellent point to start. Just use qt_ifcodegen_generate CMake function for QtIF generator like below:

QtIF提供其测试模板。生成的测试是一个很好的起点。只需为QtIF生成器使用qt_ifcodegen_generate CMake函数,如下所示:

qt_ifcodegen_generate(
  IDL_FILES [PATH_TO]/FILENAME.qface
  TEMPLATE test
)

QtIF will generate two files per each interface defined in the qface file: header (tst_[INTERFACENAME].h) and cpp (tst_[INTERFACENAME].cpp). Those files contain declarations and definitions of tests that check: connections to (fake) backends, changing values from the (fake) backend/frontend, signals, and methods. That is something that can be easily and quickly integrated and used in your project.

QtIF将为qface文件中定义的每个接口生成两个文件:header(tst_[INTERFACENAME].h)和cpp(tst_[INTERFACENAME].cpp)。这些文件包含检查的测试的声明和定义:到(假)后端的连接、更改(假)后端/前端的值、信号和方法。这是一种可以轻松快速地集成并在项目中使用的东西。

 Module tests

模组测试

Module tests are the second type of test for Qt IF Android Vehicle Properties in QtAA. They are used for testing the full feature (using the actual frontend and backend). The QtIF generator also generates backends, frontend, and test scenarios are also generated with :

​模块测试是QtAA中Android车辆属性的第二类测试。它们用于测试完整功能(使用实际的前端和后端)。QtIF生成器还生成后端、前端和测试场景,这些场景还通过以下方式生成:

 Android Automotive的Qt测试_第1张图片

There are more than ten interfaces, each of them with multiple vehicle properties. Creating and maintaining tests per each property and backend combination would be too much manual work. The QtIF generator helps avoid copied code and gives you an easy way to iterate for each interface and property. It also offers a possibility to receive getter/setter function names or default properties value. Let's look at the following code:

有十多个接口,每个接口都具有多个车辆属性。为每个属性和后端组合创建和维护测试将是太多的手动工作。QtIF生成器有助于避免复制代码,并为每个接口和属性提供了一种简单的迭代方法。它还提供了接收getter/setter函数名或默认属性值的可能性。让我们看看以下代码:

{ % for interface in module.interfaces %}
  { %for property in interface.properties %}
     toSet = 
        ;
    QSignalSpy Spy(m_, 
        SIGNAL(Changed()));
    QVERIFY(Spy.isValid());
    QCOMPARE(Spy.count(), 0);

    m_->(toSet);
    QVERIFY(Spy.wait());
    QCOMPARE(Spy.count(), 1);
    QCOMPARE(m_->(), toSet);
  { % endfor %}
{ % endfor %}

Code will be generated for each property in each interface in the QFace file. Let's look at the generated code for the fanSpeed property in the QIFHvac interface:

将为QFace文件中每个接口中的每个属性生成代码。让我们看看在QIFHvac接口中为fanSpeed属性生成的代码:

int toSetFanSpeed = 111;
QSignalSpy fanSpeedSpy(m_qifhvac_test, SIGNAL(fanSpeedChanged(int)));
QVERIFY(fanSpeedSpy.isValid());
QCOMPARE(fanSpeedSpy.count(), 0);

m_qifhvac_test->setFanSpeed(toSetFanSpeed);
QVERIFY(fanSpeedSpy.wait());
QCOMPARE(fanSpeedSpy.count(), 1);
QCOMPARE(m_qifhvac_test->fanSpeed(), toSetFanSpeed);
QtIfAndroidVehicleProperties::VehicleHvacFanDirections toSetFanDirection = 
  QtIfAndroidVehicleProperties::VEHICLE_HVAC_FAN_DIRECTION_DEFROST_AND_FLOOR;
QSignalSpy fanDirectionSpy(m_qifhvac_test, 
  SIGNAL(fanDirectionChanged(QtIfAndroidVehicleProperties::VehicleHvacFanDirections)));
QVERIFY(fanDirectionSpy.isValid());
QCOMPARE(fanDirectionSpy.count(), 0);

As you can see, using QtIF to generate test scenarios can be helpful. Just imagine you are manually writing this code for each property. The test will adjust during configuration when you add, rename, or remove a property from your qface file.

如您所见,使用QtIF生成测试场景会很有帮助。假设您正在为每个属性手动编写此代码。当您在qface文件中添加、重命名或删除属性时,测试将在配置期间进行调整。

你可能感兴趣的:(QtBlog,android,qt)