BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
widgetutils.test.cpp File Reference

Implements class CLASS? More...

Include dependency graph for widgetutils.test.cpp:

Go to the source code of this file.

Classes

class  WidgetUtilsTest
 Testing functions from utils. More...
 

Functions

 TEST_F (WidgetUtilsTest, ClickableText)
 
 TEST_F (WidgetUtilsTest, fromStringList)
 
 TEST_F (WidgetUtilsTest, ProjectWindowTitle)
 
 TEST_F (WidgetUtilsTest, toFromByteArray)
 
 TEST_F (WidgetUtilsTest, toStringList)
 
 TEST_F (WidgetUtilsTest, WithTildeHomePath)
 Test of WithTildeHomePath function. More...
 

Detailed Description

Implements class CLASS?

Homepage:\n http://www.bornagainproject.org
License:\n GNU General Public License v3 or higher (see COPYING)
Authors
Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)

Definition in file widgetutils.test.cpp.

Function Documentation

◆ TEST_F() [1/6]

TEST_F ( WidgetUtilsTest  ,
ClickableText   
)

Definition at line 75 of file widgetutils.test.cpp.

76 {
77  EXPECT_EQ(Utils::ClickableText("abc", "site.com"), QString("<a href=\"site.com\">abc</a>"));
78 }
MVVM_VIEW_EXPORT QString ClickableText(const QString &text, const QString &tag={})
Returns text wrapped into 'href' tag to provide clickable links in QLabel.

References ModelView::Utils::ClickableText().

Here is the call graph for this function:

◆ TEST_F() [2/6]

TEST_F ( WidgetUtilsTest  ,
fromStringList   
)

Definition at line 87 of file widgetutils.test.cpp.

88 {
89  using vec_t = std::vector<std::string>;
90  EXPECT_EQ(Utils::fromStringList(QStringList()), vec_t());
91  EXPECT_EQ(Utils::fromStringList(QStringList({"abc", "cde"})), vec_t({"abc", "cde"}));
92 }
MVVM_VIEW_EXPORT std::vector< std::string > fromStringList(const QStringList &string_list)
Converts vector of strings to QStringList.

References ModelView::Utils::fromStringList().

Here is the call graph for this function:

◆ TEST_F() [3/6]

TEST_F ( WidgetUtilsTest  ,
ProjectWindowTitle   
)

Definition at line 54 of file widgetutils.test.cpp.

55 {
56  // untitled and unmodified project
57  EXPECT_EQ(Utils::ProjectWindowTitle(QString(""), false), "Untitled");
58 
59  // untitled and modified project
60  EXPECT_EQ(Utils::ProjectWindowTitle(QString(""), true), "*Untitled");
61 
62  // unmodified project without projectDir
63  EXPECT_EQ(Utils::ProjectWindowTitle(QString("Untitled"), false), "Untitled");
64 
65  // modified project without projectDir
66  EXPECT_EQ(Utils::ProjectWindowTitle(QString("Untitled"), true), "*Untitled");
67 
68  // unmodified project with projectDir
69  EXPECT_EQ(Utils::ProjectWindowTitle(QString("/home/user/project1"), false), "project1");
70 
71  // modified project with projectDir
72  EXPECT_EQ(Utils::ProjectWindowTitle(QString("/home/user/project1"), true), "*project1");
73 }
MVVM_MODEL_EXPORT std::string ProjectWindowTitle(const ProjectInterface &project)
Returns a MainWindow title for given project.

References ModelView::Utils::ProjectWindowTitle().

Here is the call graph for this function:

◆ TEST_F() [4/6]

TEST_F ( WidgetUtilsTest  ,
toFromByteArray   
)

Definition at line 94 of file widgetutils.test.cpp.

95 {
96  QStringList expected = QStringList() << "aaa"
97  << "bbb"
98  << "ccc";
99 
100  auto array = Utils::serialize(expected);
101  EXPECT_EQ(Utils::deserialize(array), expected);
102 }
MVVM_VIEW_EXPORT QStringList deserialize(const QByteArray &byteArray)
Converts byte array to vector of strings.
MVVM_VIEW_EXPORT QByteArray serialize(const QStringList &data)
Converts vector of strings to byte array.

References ModelView::Utils::deserialize(), and ModelView::Utils::serialize().

Here is the call graph for this function:

◆ TEST_F() [5/6]

TEST_F ( WidgetUtilsTest  ,
toStringList   
)

Definition at line 80 of file widgetutils.test.cpp.

81 {
82  using vec_t = std::vector<std::string>;
83  EXPECT_EQ(Utils::toStringList(vec_t()), QStringList());
84  EXPECT_EQ(Utils::toStringList(vec_t({"abc", "cde"})), QStringList({"abc", "cde"}));
85 }
MVVM_VIEW_EXPORT QStringList toStringList(const std::vector< std::string > &vec)
Converts vector of strings to QStringList.

References ModelView::Utils::toStringList().

Here is the call graph for this function:

◆ TEST_F() [6/6]

TEST_F ( WidgetUtilsTest  ,
WithTildeHomePath   
)

Test of WithTildeHomePath function.

Definition at line 34 of file widgetutils.test.cpp.

35 {
37  auto test_dir = QString::fromStdString(TestUtils::TestOutputDir());
38  EXPECT_EQ(Utils::WithTildeHomePath(test_dir), test_dir);
39  } else {
40  auto home_path = QDir::homePath();
41  auto test_dir = QString::fromStdString(TestUtils::TestOutputDir());
42  auto expected = test_dir.startsWith(home_path)
43  ? QString("~") + test_dir.mid(home_path.size())
44  : test_dir;
45 
46  // "/home/user/build-debug/test_output" -> ~/build-debug/test_output"
47  EXPECT_EQ(Utils::WithTildeHomePath(test_dir).toStdString(), expected.toStdString());
48 
49  EXPECT_EQ(Utils::WithTildeHomePath("/opt/sw/build").toStdString(),
50  std::string("/opt/sw/build"));
51  }
52 }
MVVM_VIEW_EXPORT QString WithTildeHomePath(const QString &path)
Returns a string where Linux path to the file is striped using '~/'.
Definition: widgetutils.cpp:79
MVVM_VIEW_EXPORT bool IsWindowsHost()
Returns true if it is Windows.
Definition: widgetutils.cpp:52
std::string TestOutputDir()
Returns full path to the main test folder, as defined by CMake at compile time.
Definition: test_utils.cpp:35

References ModelView::Utils::IsWindowsHost(), TestUtils::TestOutputDir(), and ModelView::Utils::WithTildeHomePath().

Here is the call graph for this function: