aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/tests.update.cpp
diff options
context:
space:
mode:
authorAlexander Saprykin <xelfium@gmail.com>2018-05-26 13:27:14 +0200
committerGitHub <noreply@github.com>2018-05-26 13:27:14 +0200
commit4ce5f064282c3a8d8d710aa82af7aa346b0c6dd5 (patch)
treed95c9490352eb73f078d34a33bc4bb44ac9fa48b /toolsrc/src/tests.update.cpp
parentfb689bd13dd6ba563a885d71fff1dd2b32a615db (diff)
parent2ac7527b40b1dbeb7856b9f763362c1e139e2ca9 (diff)
downloadvcpkg-4ce5f064282c3a8d8d710aa82af7aa346b0c6dd5.tar.gz
vcpkg-4ce5f064282c3a8d8d710aa82af7aa346b0c6dd5.zip
Merge pull request #1 from Microsoft/master
Update vcpkg from upstream
Diffstat (limited to 'toolsrc/src/tests.update.cpp')
-rw-r--r--toolsrc/src/tests.update.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/toolsrc/src/tests.update.cpp b/toolsrc/src/tests.update.cpp
new file mode 100644
index 000000000..b6e487c17
--- /dev/null
+++ b/toolsrc/src/tests.update.cpp
@@ -0,0 +1,106 @@
+#include "tests.pch.h"
+
+#include <tests.utils.h>
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+using namespace vcpkg;
+using namespace vcpkg::Update;
+
+namespace UnitTest1
+{
+ using Pgh = std::vector<std::unordered_map<std::string, std::string>>;
+
+ class UpdateTests : public TestClass<UpdateTests>
+ {
+ TEST_METHOD(find_outdated_packages_basic)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFile> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "0"}}}));
+ map.emplace("a", std::move(*scf));
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ Assert::AreEqual(size_t(1), pkgs.size());
+ Assert::AreEqual("2", pkgs[0].version_diff.left.to_string().c_str());
+ Assert::AreEqual("0", pkgs[0].version_diff.right.to_string().c_str());
+ }
+
+ TEST_METHOD(find_outdated_packages_features)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ status_paragraphs.push_back(make_status_feature_pgh("a", "b"));
+ status_paragraphs.back()->package.version = "2";
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFile> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "0"}}}));
+ map.emplace("a", std::move(*scf));
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ Assert::AreEqual(size_t(1), pkgs.size());
+ Assert::AreEqual("2", pkgs[0].version_diff.left.to_string().c_str());
+ Assert::AreEqual("0", pkgs[0].version_diff.right.to_string().c_str());
+ }
+
+ TEST_METHOD(find_outdated_packages_features_2)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ status_paragraphs.push_back(make_status_feature_pgh("a", "b"));
+ status_paragraphs.back()->package.version = "0";
+ status_paragraphs.back()->state = InstallState::NOT_INSTALLED;
+ status_paragraphs.back()->want = Want::PURGE;
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFile> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "0"}}}));
+ map.emplace("a", std::move(*scf));
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ Assert::AreEqual(size_t(1), pkgs.size());
+ Assert::AreEqual("2", pkgs[0].version_diff.left.to_string().c_str());
+ Assert::AreEqual("0", pkgs[0].version_diff.right.to_string().c_str());
+ }
+
+ TEST_METHOD(find_outdated_packages_none)
+ {
+ std::vector<std::unique_ptr<StatusParagraph>> status_paragraphs;
+ status_paragraphs.push_back(make_status_pgh("a"));
+ status_paragraphs.back()->package.version = "2";
+
+ StatusParagraphs status_db(std::move(status_paragraphs));
+
+ std::unordered_map<std::string, SourceControlFile> map;
+ auto scf = unwrap(SourceControlFile::parse_control_file(Pgh{{{"Source", "a"}, {"Version", "2"}}}));
+ map.emplace("a", std::move(*scf));
+ Dependencies::MapPortFileProvider provider(map);
+
+ auto pkgs = SortedVector<OutdatedPackage>(Update::find_outdated_packages(provider, status_db),
+ &OutdatedPackage::compare_by_name);
+
+ Assert::AreEqual(size_t(0), pkgs.size());
+ }
+ };
+}