File indexing completed on 2024-05-19 05:42:18
0001 // ct_lvtqtc_inputdialog.t.cpp -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 #include <ct_lvtqtc_inputdialog.h> 0020 0021 #include <QLineEdit> 0022 #include <QSpinBox> 0023 0024 #include <catch2-local-includes.h> 0025 0026 #include <ct_lvttst_fixture_qt.h> 0027 0028 TEST_CASE_METHOD(QTApplicationFixture, "Usage with prepareFields") 0029 { 0030 Codethink::lvtqtc::InputDialog dlg; 0031 0032 // a is the key value, and the objectName of the lineEdit. SomeText is the label text. 0033 dlg.prepareFields({{"a", QString("SomeText")}, {"b", QString("OtherText")}}); 0034 0035 // QLineEdit is internal and not exposed API. 0036 const auto lineEdits = dlg.findChildren<QLineEdit *>(); 0037 for (auto *lineEdit : lineEdits) { 0038 lineEdit->setText(lineEdit->objectName()); 0039 } 0040 0041 REQUIRE(std::any_cast<QString>(dlg.fieldValue("a")) == "a"); 0042 REQUIRE(std::any_cast<QString>(dlg.fieldValue("b")) == "b"); 0043 } 0044 0045 TEST_CASE_METHOD(QTApplicationFixture, "Usage with Add*Field") 0046 { 0047 Codethink::lvtqtc::InputDialog dlg; 0048 0049 dlg.addTextField("a", "label"); 0050 dlg.addComboBoxField("b", "otherlabel", {QString("one"), QString("two"), QString("three")}); 0051 dlg.addSpinBoxField("c", "numericLabel", {0, 99}, 50); 0052 dlg.finish(); 0053 0054 const auto lineEdits = dlg.findChildren<QLineEdit *>(); 0055 for (auto *lineEdit : lineEdits) { 0056 lineEdit->setText(lineEdit->objectName()); 0057 } 0058 auto *spinBox = dlg.findChildren<QSpinBox *>().at(0); 0059 spinBox->setValue(10); 0060 0061 REQUIRE(std::any_cast<QString>(dlg.fieldValue("a")) == "a"); 0062 REQUIRE(std::any_cast<QString>(dlg.fieldValue("b")) == "one"); 0063 REQUIRE(std::any_cast<int>(dlg.fieldValue("c")) == 10); 0064 }