| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |    2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 
|    3  * |    3  * | 
|    4  *  Use of this source code is governed by a BSD-style license |    4  *  Use of this source code is governed by a BSD-style license | 
|    5  *  that can be found in the LICENSE file in the root of the source |    5  *  that can be found in the LICENSE file in the root of the source | 
|    6  *  tree. An additional intellectual property rights grant can be found |    6  *  tree. An additional intellectual property rights grant can be found | 
|    7  *  in the file PATENTS.  All contributing project authors may |    7  *  in the file PATENTS.  All contributing project authors may | 
|    8  *  be found in the AUTHORS file in the root of the source tree. |    8  *  be found in the AUTHORS file in the root of the source tree. | 
|    9  */ |    9  */ | 
|   10  |   10  | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   51  private: |   51  private: | 
|   52   static std::string original_working_dir_; |   52   static std::string original_working_dir_; | 
|   53 }; |   53 }; | 
|   54  |   54  | 
|   55 std::string FileUtilsTest::original_working_dir_ = ""; |   55 std::string FileUtilsTest::original_working_dir_ = ""; | 
|   56  |   56  | 
|   57 // Tests that the project output dir path is returned for the default working |   57 // Tests that the project output dir path is returned for the default working | 
|   58 // directory that is automatically set when the test executable is launched. |   58 // directory that is automatically set when the test executable is launched. | 
|   59 // The test is not fully testing the implementation, since we cannot be sure |   59 // The test is not fully testing the implementation, since we cannot be sure | 
|   60 // of where the executable was launched from. |   60 // of where the executable was launched from. | 
|   61 #if defined(WEBRTC_ANDROID) |   61 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 
|   62 #define MAYBE_OutputPathFromUnchangedWorkingDir \ |   62 #define MAYBE_OutputPathFromUnchangedWorkingDir \ | 
|   63   DISABLED_OutputPathFromUnchangedWorkingDir |   63   DISABLED_OutputPathFromUnchangedWorkingDir | 
|   64 #else |   64 #else | 
|   65 #define MAYBE_OutputPathFromUnchangedWorkingDir \ |   65 #define MAYBE_OutputPathFromUnchangedWorkingDir \ | 
|   66   OutputPathFromUnchangedWorkingDir |   66   OutputPathFromUnchangedWorkingDir | 
|   67 #endif |   67 #endif | 
|   68 TEST_F(FileUtilsTest, MAYBE_OutputPathFromUnchangedWorkingDir) { |   68 TEST_F(FileUtilsTest, MAYBE_OutputPathFromUnchangedWorkingDir) { | 
|   69   std::string path = webrtc::test::OutputPath(); |   69   std::string path = webrtc::test::OutputPath(); | 
|   70   std::string expected_end = "out"; |   70   std::string expected_end = "out"; | 
|   71   expected_end = kPathDelimiter + expected_end + kPathDelimiter; |   71   expected_end = kPathDelimiter + expected_end + kPathDelimiter; | 
|   72   ASSERT_EQ(path.length() - expected_end.length(), path.find(expected_end)); |   72   ASSERT_EQ(path.length() - expected_end.length(), path.find(expected_end)); | 
|   73 } |   73 } | 
|   74  |   74  | 
|   75 // Tests with current working directory set to a directory higher up in the |   75 // Tests with current working directory set to a directory higher up in the | 
|   76 // directory tree than the project root dir. |   76 // directory tree than the project root dir. | 
|   77 #if defined(WEBRTC_ANDROID) || defined(WIN32) |   77 #if defined(WEBRTC_ANDROID) || defined(WIN32) || defined(WEBRTC_IOS) | 
|   78 #define MAYBE_OutputPathFromRootWorkingDir DISABLED_OutputPathFromRootWorkingDir |   78 #define MAYBE_OutputPathFromRootWorkingDir DISABLED_OutputPathFromRootWorkingDir | 
|   79 #else |   79 #else | 
|   80 #define MAYBE_OutputPathFromRootWorkingDir OutputPathFromRootWorkingDir |   80 #define MAYBE_OutputPathFromRootWorkingDir OutputPathFromRootWorkingDir | 
|   81 #endif |   81 #endif | 
|   82 TEST_F(FileUtilsTest, MAYBE_OutputPathFromRootWorkingDir) { |   82 TEST_F(FileUtilsTest, MAYBE_OutputPathFromRootWorkingDir) { | 
|   83   ASSERT_EQ(0, chdir(kPathDelimiter)); |   83   ASSERT_EQ(0, chdir(kPathDelimiter)); | 
|   84   ASSERT_EQ("./", webrtc::test::OutputPath()); |   84   ASSERT_EQ("./", webrtc::test::OutputPath()); | 
|   85 } |   85 } | 
|   86  |   86  | 
|   87 TEST_F(FileUtilsTest, TempFilename) { |   87 TEST_F(FileUtilsTest, TempFilename) { | 
|   88   std::string temp_filename = webrtc::test::TempFilename( |   88   std::string temp_filename = webrtc::test::TempFilename( | 
|   89       webrtc::test::OutputPath(), "TempFilenameTest"); |   89       webrtc::test::OutputPath(), "TempFilenameTest"); | 
|   90   ASSERT_TRUE(webrtc::test::FileExists(temp_filename)) |   90   ASSERT_TRUE(webrtc::test::FileExists(temp_filename)) | 
|   91       << "Couldn't find file: " << temp_filename; |   91       << "Couldn't find file: " << temp_filename; | 
|   92   remove(temp_filename.c_str()); |   92   remove(temp_filename.c_str()); | 
|   93 } |   93 } | 
|   94  |   94  | 
|   95 // Only tests that the code executes |   95 // Only tests that the code executes | 
|   96 TEST_F(FileUtilsTest, CreateDir) { |   96 #if defined(WEBRTC_IOS) | 
 |   97 #define MAYBE_CreateDir DISABLED_CreateDir | 
 |   98 #else | 
 |   99 #define MAYBE_CreateDir CreateDir | 
 |  100 #endif | 
 |  101 TEST_F(FileUtilsTest, MAYBE_CreateDir) { | 
|   97   std::string directory = "fileutils-unittest-empty-dir"; |  102   std::string directory = "fileutils-unittest-empty-dir"; | 
|   98   // Make sure it's removed if a previous test has failed: |  103   // Make sure it's removed if a previous test has failed: | 
|   99   remove(directory.c_str()); |  104   remove(directory.c_str()); | 
|  100   ASSERT_TRUE(webrtc::test::CreateDir(directory)); |  105   ASSERT_TRUE(webrtc::test::CreateDir(directory)); | 
|  101   remove(directory.c_str()); |  106   remove(directory.c_str()); | 
|  102 } |  107 } | 
|  103  |  108  | 
|  104 TEST_F(FileUtilsTest, WorkingDirReturnsValue) { |  109 TEST_F(FileUtilsTest, WorkingDirReturnsValue) { | 
|  105   // Hard to cover all platforms. Just test that it returns something without |  110   // Hard to cover all platforms. Just test that it returns something without | 
|  106   // crashing: |  111   // crashing: | 
|  107   std::string working_dir = webrtc::test::WorkingDir(); |  112   std::string working_dir = webrtc::test::WorkingDir(); | 
|  108   ASSERT_GT(working_dir.length(), 0u); |  113   ASSERT_GT(working_dir.length(), 0u); | 
|  109 } |  114 } | 
|  110  |  115  | 
|  111 // Due to multiple platforms, it is hard to make a complete test for |  116 // Due to multiple platforms, it is hard to make a complete test for | 
|  112 // ResourcePath. Manual testing has been performed by removing files and |  117 // ResourcePath. Manual testing has been performed by removing files and | 
|  113 // verified the result confirms with the specified documentation for the |  118 // verified the result confirms with the specified documentation for the | 
|  114 // function. |  119 // function. | 
|  115 TEST_F(FileUtilsTest, ResourcePathReturnsValue) { |  120 TEST_F(FileUtilsTest, ResourcePathReturnsValue) { | 
|  116   std::string resource = webrtc::test::ResourcePath(kTestName, kExtension); |  121   std::string resource = webrtc::test::ResourcePath(kTestName, kExtension); | 
|  117   ASSERT_GT(resource.find(kTestName), 0u); |  122   ASSERT_GT(resource.find(kTestName), 0u); | 
|  118   ASSERT_GT(resource.find(kExtension), 0u); |  123   ASSERT_GT(resource.find(kExtension), 0u); | 
|  119 } |  124 } | 
|  120  |  125  | 
|  121 TEST_F(FileUtilsTest, ResourcePathFromRootWorkingDir) { |  126 TEST_F(FileUtilsTest, ResourcePathFromRootWorkingDir) { | 
|  122   ASSERT_EQ(0, chdir(kPathDelimiter)); |  127   ASSERT_EQ(0, chdir(kPathDelimiter)); | 
|  123   std::string resource = webrtc::test::ResourcePath(kTestName, kExtension); |  128   std::string resource = webrtc::test::ResourcePath(kTestName, kExtension); | 
 |  129 #if !defined(WEBRTC_IOS) | 
|  124   ASSERT_NE(resource.find("resources"), std::string::npos); |  130   ASSERT_NE(resource.find("resources"), std::string::npos); | 
 |  131 #endif | 
|  125   ASSERT_GT(resource.find(kTestName), 0u); |  132   ASSERT_GT(resource.find(kTestName), 0u); | 
|  126   ASSERT_GT(resource.find(kExtension), 0u); |  133   ASSERT_GT(resource.find(kExtension), 0u); | 
|  127 } |  134 } | 
|  128  |  135  | 
|  129 TEST_F(FileUtilsTest, GetFileSizeExistingFile) { |  136 TEST_F(FileUtilsTest, GetFileSizeExistingFile) { | 
|  130   // Create a file with some dummy data in. |  137   // Create a file with some dummy data in. | 
|  131   std::string temp_filename = webrtc::test::TempFilename( |  138   std::string temp_filename = webrtc::test::TempFilename( | 
|  132       webrtc::test::OutputPath(), "fileutils_unittest"); |  139       webrtc::test::OutputPath(), "fileutils_unittest"); | 
|  133   FILE* file = fopen(temp_filename.c_str(), "wb"); |  140   FILE* file = fopen(temp_filename.c_str(), "wb"); | 
|  134   ASSERT_TRUE(file != NULL) << "Failed to open file: " << temp_filename; |  141   ASSERT_TRUE(file != NULL) << "Failed to open file: " << temp_filename; | 
|  135   ASSERT_GT(fprintf(file, "%s",  "Dummy data"), 0) << |  142   ASSERT_GT(fprintf(file, "%s",  "Dummy data"), 0) << | 
|  136       "Failed to write to file: " << temp_filename; |  143       "Failed to write to file: " << temp_filename; | 
|  137   fclose(file); |  144   fclose(file); | 
|  138   ASSERT_GT(webrtc::test::GetFileSize(std::string(temp_filename.c_str())), 0u); |  145   ASSERT_GT(webrtc::test::GetFileSize(std::string(temp_filename.c_str())), 0u); | 
|  139   remove(temp_filename.c_str()); |  146   remove(temp_filename.c_str()); | 
|  140 } |  147 } | 
|  141  |  148  | 
|  142 TEST_F(FileUtilsTest, GetFileSizeNonExistingFile) { |  149 TEST_F(FileUtilsTest, GetFileSizeNonExistingFile) { | 
|  143   ASSERT_EQ(0u, webrtc::test::GetFileSize("non-existing-file.tmp")); |  150   ASSERT_EQ(0u, webrtc::test::GetFileSize("non-existing-file.tmp")); | 
|  144 } |  151 } | 
|  145  |  152  | 
|  146 }  // namespace webrtc |  153 }  // namespace webrtc | 
| OLD | NEW |