diff --git a/src/model_editor/test/Utilities_GTest.cpp b/src/model_editor/test/Utilities_GTest.cpp index fc14eebcc..3fadfdaef 100644 --- a/src/model_editor/test/Utilities_GTest.cpp +++ b/src/model_editor/test/Utilities_GTest.cpp @@ -11,6 +11,7 @@ #include "../Utilities.hpp" #include +#include using openstudio::toPath; using openstudio::toQString; @@ -113,3 +114,35 @@ TEST_F(ModelEditorFixture, Path_Conversions) { EXPECT_EQ(t, std::string(toQString(toString(p)).toUtf8())); EXPECT_EQ(t, toString(toPath(toQString(toString(p))))); } + +TEST_F(ModelEditorFixture, MorePath_Conversions) { + struct PathTestCase + { + std::string inputPath; + QString expectedPath; + QString expectedUrl; + }; + + std::vector testCases = { + {"C:\\Users\\Test\\eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"}, + {"C:/Users/Test/eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"}, + {"C:\\Users/Test/eplustbl.html", "C:/Users/Test/eplustbl.html", "file:///C:/Users/Test/eplustbl.html"}, + {"C:\\Users\\Test# ^\\eplustbl.html", "C:/Users/Test# ^/eplustbl.html", "file:///C:/Users/Test%23%20%5E/eplustbl.html"}, + {"/home/Test/eplustbl.html", "/home/Test/eplustbl.html", "file:///home/Test/eplustbl.html"}, + {"/home/Test# ^/eplustbl.html", "/home/Test# ^/eplustbl.html", "file:///home/Test%23%20%5E/eplustbl.html"}, + }; + + // double check the conversions in openstudio_lib/ResultsTabView.cpp + for (const auto& testCase : testCases) { + openstudio::path osPath = toPath(testCase.inputPath); + QString qPath = toQString(osPath); + EXPECT_EQ(qPath, testCase.expectedPath); + QUrl url = QUrl::fromLocalFile(qPath); + EXPECT_EQ(url.toString(QUrl::FullyEncoded), testCase.expectedUrl); + + std::cout << "Input: " << testCase.inputPath << ", " + << "OS Path: " << osPath << ", " + << "QPath: " << qPath.toStdString() << ", " + << "Url: " << url.toString().toStdString() << std::endl; + } +} \ No newline at end of file diff --git a/src/openstudio_lib/ResultsTabView.cpp b/src/openstudio_lib/ResultsTabView.cpp index 564739a2b..4445cdfea 100644 --- a/src/openstudio_lib/ResultsTabView.cpp +++ b/src/openstudio_lib/ResultsTabView.cpp @@ -301,7 +301,6 @@ void ResultsView::populateComboBox(const std::vector& reports) QString fullPathString = toQString(report); QFile file(fullPathString); - fullPathString.prepend("file:///"); if (openstudio::toString(report.filename()) == "eplustbl.html" || openstudio::toString(report.filename()) == "eplustbl.htm") { @@ -360,7 +359,7 @@ void ResultsView::comboBoxChanged(int index) { m_progressBar->setError(false); - QUrl url(filename); + QUrl url = QUrl::fromLocalFile(filename); m_view->load(url); }