diff options
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 |