diff --git a/tdd_intro/homework/07_filecopier/test.cpp b/tdd_intro/homework/07_filecopier/test.cpp index be20cab..7b16ddc 100644 --- a/tdd_intro/homework/07_filecopier/test.cpp +++ b/tdd_intro/homework/07_filecopier/test.cpp @@ -20,3 +20,144 @@ You can start with GMock from https://goo.gl/j7EkQX, good luck! #include #include +/* 1. Copy single file + 2. Attempt to copy unexistant file + 3. Copy empty folder + 4. Attempt to copy unexistant folder + 5. Copy folder with single file + 6. Copy folder with several files + 7. Copy folder with several files and other folders */ + +const std::string s_singleFileSrcPath("C://singleFile"); +const std::string s_singleFileDstPath("D://singleFile"); + +const std::string s_unexistantFileSrcPath("C://unexistantFile"); +const std::string s_unexistantFileDstPath("D://unexistantFile"); + +const std::string s_emptyFolderSrcPath("C://emptyFolder"); +const std::string s_emptyFolderDstPath("D://emptyFolder"); + +const std::string s_unexistantFolderSrcPath("C://unexistantFolder"); +const std::string s_unexistantFolderDstPath("D://unexistantFolder"); + +const std::string s_singleFileFolderSrcPath("C://singleFileFolder"); +const std::string s_singleFileFolderDstPath("D://singleFileFolder"); +const std::string s_singleFileFolderFileName("file"); +const std::string s_singleFileFolderFileSrc("C://singleFileFolder//file"); +const std::string s_singleFileFolderFileDst("D://singleFileFolder//file"); + +class IFileCopier +{ +public: + ~IFileCopier(){} + virtual void CopyFile(const std::string& src, const std::string& dst) = 0; + virtual void CopyFolder(const std::string& src, const std::string& dst) = 0; + + virtual bool CheckIfExists(const std::string& file) = 0; + virtual bool IsFolder(const std::string& path) = 0; +}; + +class FileCopierMock : public IFileCopier +{ +public: + MOCK_METHOD2(CopyFile, void(const std::string&, const std::string&)); + MOCK_METHOD2(CopyFolder, void(const std::string&, const std::string&)); + + MOCK_METHOD1(CheckIfExists, bool(const std::string&)); + MOCK_METHOD1(IsFolder, bool(const std::string&)); +}; + +class FileCopier +{ +public: + FileCopier(IFileCopier& fileCopier); + void Copy(const std::string& src, const std::string& dst); +private: + IFileCopier& m_fileCopier; +}; + +FileCopier::FileCopier(IFileCopier &fileCopier) + : m_fileCopier(fileCopier) +{ +} + +void FileCopier::Copy(const std::string &src, const std::string &dst) +{ + if (m_fileCopier.CheckIfExists(src)) + { + if (m_fileCopier.IsFolder(src)) + { + m_fileCopier.CopyFolder(src, dst); + } + else + { + m_fileCopier.CopyFile(src, dst); + } + } +} + +TEST(FileCopier, CopySingleFile) +{ + FileCopierMock mock; + FileCopier fileCopier(mock); + + EXPECT_CALL(mock, CheckIfExists(s_singleFileSrcPath)).WillOnce(testing::Return(true)); + EXPECT_CALL(mock, IsFolder(s_singleFileSrcPath)).WillOnce(testing::Return(false)); + EXPECT_CALL(mock, CopyFile(s_singleFileSrcPath, s_singleFileDstPath)).Times(1); + EXPECT_CALL(mock, CopyFolder(testing::_, testing::_)).Times(0); + + fileCopier.Copy(s_singleFileSrcPath, s_singleFileDstPath); +} + +TEST(FileCopier, CopyUnexistantFile) +{ + FileCopierMock mock; + FileCopier fileCopier(mock); + + EXPECT_CALL(mock, CheckIfExists(s_unexistantFileSrcPath)).WillOnce(testing::Return(false)); + EXPECT_CALL(mock, IsFolder(testing::_)).Times(0); + EXPECT_CALL(mock, CopyFile(testing::_, testing::_)).Times(0); + EXPECT_CALL(mock, CopyFolder(testing::_, testing::_)).Times(0); + + fileCopier.Copy(s_unexistantFileSrcPath, s_unexistantFileDstPath); +} + +TEST(FileCopier, CopyEmptyFolder) +{ + FileCopierMock mock; + FileCopier fileCopier(mock); + + EXPECT_CALL(mock, CheckIfExists(s_emptyFolderSrcPath)).WillOnce(testing::Return(true)); + EXPECT_CALL(mock, IsFolder(s_emptyFolderSrcPath)).WillOnce(testing::Return(true)); + EXPECT_CALL(mock, CopyFile(testing::_, testing::_)).Times(0); + EXPECT_CALL(mock, CopyFolder(s_emptyFolderSrcPath, s_emptyFolderDstPath)).Times(1); + + fileCopier.Copy(s_emptyFolderSrcPath, s_emptyFolderDstPath); +} + +TEST(FileCopier, CopyUnexistantFolder) +{ + FileCopierMock mock; + FileCopier fileCopier(mock); + + EXPECT_CALL(mock, CheckIfExists(s_unexistantFolderSrcPath)).WillOnce(testing::Return(false)); + EXPECT_CALL(mock, IsFolder(testing::_)).Times(0); + EXPECT_CALL(mock, CopyFile(testing::_, testing::_)).Times(0); + EXPECT_CALL(mock, CopyFolder(testing::_, testing::_)).Times(0); + + fileCopier.Copy(s_unexistantFolderSrcPath, s_unexistantFolderDstPath); +} + +TEST(FileCopier, CopyFolderWithSingleFile) +{ + FileCopierMock mock; + FileCopier fileCopier(mock); + + EXPECT_CALL(mock, CheckIfExists(s_unexistantFolderSrcPath)).WillOnce(testing::Return(true)); + EXPECT_CALL(mock, IsFolder(s_emptyFolderSrcPath)).WillOnce(testing::Return(true)); + EXPECT_CALL(mock, CopyFolder(s_singleFileFolderSrcPath, s_singleFileFolderDstPath)).Times(1); + EXPECT_CALL(mock, CopyFile(s_singleFileFolderFileSrc, s_singleFileFolderFileDst)).Times(1); + + fileCopier.Copy(s_singleFileFolderSrcPath, s_singleFileFolderDstPath); +} + diff --git a/tdd_intro/tdd_intro.pro.user b/tdd_intro/tdd_intro.pro.user index a2f1674..784a476 100644 --- a/tdd_intro/tdd_intro.pro.user +++ b/tdd_intro/tdd_intro.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {a9e7f687-ac9f-466e-a5b0-c81b575a0a1d} + {950e75d0-15c4-4cbb-8e75-9217fe27f405} ProjectExplorer.Project.ActiveTarget @@ -59,14 +59,14 @@ ProjectExplorer.Project.Target.0 - Qt 5.7.0 (windows) - Qt 5.7.0 (windows) - {bb54e87c-a17e-4f34-bfa2-da2794ff8a10} + Desktop Qt 5.10.0 MSVC2015 32bit + Desktop Qt 5.10.0 MSVC2015 32bit + qt.qt5.5100.win32_msvc2015_kit 0 0 - 11 + 0 - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug + C:/Users/ertev/Desktop/TDD course/tdd-course-2/build-tdd_intro-Desktop_Qt_5_10_0_MSVC2015_32bit-Debug true @@ -120,7 +120,7 @@ true - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Release + C:/Users/ertev/Desktop/TDD course/tdd-course-2/build-tdd_intro-Desktop_Qt_5_10_0_MSVC2015_32bit-Release true @@ -174,7 +174,7 @@ true - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Profile + C:/Users/ertev/Desktop/TDD course/tdd-course-2/build-tdd_intro-Desktop_Qt_5_10_0_MSVC2015_32bit-Profile true @@ -286,13 +286,13 @@ chatclient - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/cleanroom/chatclient/chatclient.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/cleanroom/chatclient/chatclient.pro true cleanroom/chatclient/chatclient.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/cleanroom/chatclient + 3768 false true @@ -344,13 +344,13 @@ 01_bob - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/01_bob/01_bob.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/01_bob/01_bob.pro true homework/01_bob/01_bob.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/01_bob + 3768 false true @@ -402,13 +402,13 @@ 02_word_count - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/workshops/02_word_count/02_word_count.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/workshops/02_word_count/02_word_count.pro true workshops/02_word_count/02_word_count.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/workshops/02_word_count + 3768 false true @@ -460,13 +460,13 @@ 03_anagram 03_anagram2 - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/workshops/03_anagram/03_anagram.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/workshops/03_anagram/03_anagram.pro true workshops/03_anagram/03_anagram.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/workshops/03_anagram + 3768 false true @@ -518,13 +518,13 @@ 04_trinary_numbers 04_trinary_numbers2 - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/workshops/04_trinary_numbers/04_trinary_numbers.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/workshops/04_trinary_numbers/04_trinary_numbers.pro true workshops/04_trinary_numbers/04_trinary_numbers.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/workshops/04_trinary_numbers + 3768 false true @@ -576,13 +576,13 @@ 05_word_wrapp 05_word_wrapp2 - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/workshops/05_word_wrapp/05_word_wrapp.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/workshops/05_word_wrapp/05_word_wrapp.pro true workshops/05_word_wrapp/05_word_wrapp.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/workshops/05_word_wrapp + 3768 false true @@ -634,13 +634,13 @@ 02_leap_year - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/02_leap_year/02_leap_year.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/02_leap_year/02_leap_year.pro true homework/02_leap_year/02_leap_year.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/02_leap_year + 3768 false true @@ -692,13 +692,13 @@ 03_anagram - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/03_anagram/03_anagram.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/03_anagram/03_anagram.pro true homework/03_anagram/03_anagram.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/03_anagram + 3768 false true @@ -750,13 +750,13 @@ 04_trinary_numbers - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/04_trinary_numbers/04_trinary_numbers.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/04_trinary_numbers/04_trinary_numbers.pro true homework/04_trinary_numbers/04_trinary_numbers.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/04_trinary_numbers + 3768 false true @@ -808,13 +808,13 @@ 05_word_wrapp - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/05_word_wrapp/05_word_wrapp.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/05_word_wrapp/05_word_wrapp.pro true homework/05_word_wrapp/05_word_wrapp.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/05_word_wrapp + 3768 false true @@ -866,13 +866,13 @@ 06_bank_ocr - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/06_bank_ocr/06_bank_ocr.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/06_bank_ocr/06_bank_ocr.pro true homework/06_bank_ocr/06_bank_ocr.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/06_bank_ocr + 3768 false true @@ -924,13 +924,13 @@ 07_filecopier - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/07_filecopier/07_filecopier.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/07_filecopier/07_filecopier.pro true homework/07_filecopier/07_filecopier.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/07_filecopier + 3768 false true @@ -982,13 +982,13 @@ 08_timer - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/homework/08_timer/08_timer.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/homework/08_timer/08_timer.pro true homework/08_timer/08_timer.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/homework/08_timer + 3768 false true @@ -1040,13 +1040,13 @@ 01_fizz_buzz - Qt4ProjectManager.Qt4RunConfiguration:D:/Study/tdd-course-2/tdd_intro/workshops/01_fizz_buzz/01_fizz_buzz.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ertev/Desktop/TDD course/tdd-course-2/tdd_intro/workshops/01_fizz_buzz/01_fizz_buzz.pro true workshops/01_fizz_buzz/01_fizz_buzz.pro false - D:/Study/tdd-course-2/build-tdd_intro-Qt_5_7_0_windows-Debug/workshops/01_fizz_buzz + 3768 false true