LCOV - code coverage report
Current view: top level - sal/qa/osl/file - test_cpy_wrt_file.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 27 100.0 %
Date: 2014-11-03 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/types.h>
      21             : #include <cppunit/TestFixture.h>
      22             : #include <cppunit/extensions/HelperMacros.h>
      23             : #include <cppunit/plugin/TestPlugIn.h>
      24             : #include <osl/file.hxx>
      25             : #include <osl/thread.h>
      26             : #include <rtl/ustring.hxx>
      27             : 
      28             : using namespace osl;
      29             : 
      30             : using ::rtl::OUString;
      31             : using ::rtl::OUStringToOString;
      32             : using ::rtl::OString;
      33             : 
      34           6 : class test_osl_writeFile : public CppUnit::TestFixture
      35             : {
      36             : public:
      37           2 :     void wrt_file()
      38             :     {
      39             :         FileBase::RC err;
      40             : 
      41             :         //create a tempfile
      42           2 :         rtl::OUString aTmpFile;
      43           2 :         err = FileBase::createTempFile(NULL, NULL, &aTmpFile);
      44           2 :         CPPUNIT_ASSERT_MESSAGE("temp File creation failed", err == osl::FileBase::E_None);
      45             : 
      46             :         //now attempt to open with Create flag an existing file, should get E_EXIST
      47           4 :         File tmp_file(aTmpFile);
      48           2 :         err = tmp_file.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create);
      49             : 
      50           4 :         rtl::OString sErrorMsg = "Expected that '";
      51           2 :         sErrorMsg += rtl::OUStringToOString(aTmpFile, RTL_TEXTENCODING_ASCII_US);
      52           2 :         sErrorMsg += "' would exist!";
      53           2 :         CPPUNIT_ASSERT_MESSAGE(sErrorMsg.getStr(), err == FileBase::E_EXIST);
      54             : 
      55             :         char buffer[1];
      56           2 :         sal_uInt64 written = 0;
      57           2 :         err = tmp_file.write((void*)buffer, sizeof(buffer), written);
      58           4 :         CPPUNIT_ASSERT_MESSAGE("write on unconnected file should fail",
      59           2 :             err != osl::FileBase::E_None && written == 0);
      60             : 
      61           2 :         err = tmp_file.sync();
      62           2 :         CPPUNIT_ASSERT_MESSAGE("sync on unconnected file should fail", err != FileBase::E_None);
      63           2 :         err = tmp_file.close();
      64           2 :         CPPUNIT_ASSERT_MESSAGE("close on unconnected file should fail", err != FileBase::E_None);
      65             : 
      66           2 :         err = ::osl::File::remove(aTmpFile);
      67           4 :         CPPUNIT_ASSERT_MESSAGE("temp file should have existed", err == FileBase::E_None);
      68           2 :     }
      69             : 
      70           4 :     CPPUNIT_TEST_SUITE(test_osl_writeFile);
      71           2 :     CPPUNIT_TEST(wrt_file);
      72           4 :     CPPUNIT_TEST_SUITE_END();
      73             : };
      74             : 
      75             : // register test suites
      76           2 : CPPUNIT_TEST_SUITE_REGISTRATION(test_osl_writeFile);
      77             : 
      78           8 : CPPUNIT_PLUGIN_IMPLEMENT();
      79             : 
      80             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10