diff options
author | 2016-12-21 15:01:36 +0000 | |
---|---|---|
committer | 2016-12-21 17:23:51 +0000 | |
commit | 7de9b6f1d9748d7347fa76f5ac8d0258c79b6d70 (patch) | |
tree | e0fc695c7e65e6d0fcd9f2929de6811afdf7e734 /src/test/cpp | |
parent | fd31061d4cd99277ba1cfacd17ac316f8dfea4f5 (diff) |
Bazel client, Windows: implement ReadFile
Implement blaze_util::ReadFile on top of the
::ReadFile Windows API function.
Also implement blaze_util::AsWindowsPath so we can
convert MSYS paths to Windows widechar paths.
Add tests.
See https://github.com/bazelbuild/bazel/issues/2107
--
PiperOrigin-RevId: 142659955
MOS_MIGRATED_REVID=142659955
Diffstat (limited to 'src/test/cpp')
-rw-r--r-- | src/test/cpp/util/file_test.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/test/cpp/util/file_test.cc b/src/test/cpp/util/file_test.cc index f98ed9975a..7c15ceb816 100644 --- a/src/test/cpp/util/file_test.cc +++ b/src/test/cpp/util/file_test.cc @@ -11,10 +11,11 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +#include <stdio.h> #include <string.h> #include <memory> // unique_ptr -#include <thread> // NOLINT (to slience Google-internal linter) +#include <thread> // NOLINT (to silence Google-internal linter) #include "src/main/cpp/util/file.h" #include "src/main/cpp/util/file_platform.h" @@ -22,6 +23,8 @@ namespace blaze_util { +using std::string; + TEST(FileTest, TestNormalizePath) { ASSERT_EQ(string(""), NormalizePath("")); ASSERT_EQ(string(""), NormalizePath(".")); @@ -66,4 +69,23 @@ TEST(FileTest, TestMultiThreadedPipe) { ASSERT_EQ(0, strncmp(buffer, "hello world", 11)); } +TEST(FileTest, TestReadFile) { + const char* tempdir = getenv("TEST_TMPDIR"); + ASSERT_NE(nullptr, tempdir); + ASSERT_NE(0, tempdir[0]); + + std::string filename(JoinPath(tempdir, "test.readfile")); + FILE* fh = fopen(filename.c_str(), "wt"); + ASSERT_NE(nullptr, fh); + ASSERT_EQ(11, fwrite("hello world", 1, 11, fh)); + fclose(fh); + + std::string actual; + ASSERT_TRUE(ReadFile(filename, &actual)); + ASSERT_EQ(std::string("hello world"), actual); + + ASSERT_TRUE(ReadFile(filename, &actual, 5)); + ASSERT_EQ(std::string("hello"), actual); +} + } // namespace blaze_util |