LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/osl/file - test_cpy_wrt_file.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 27 100.0 %
Date: 2012-12-27 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           3 : class test_osl_writeFile : public CppUnit::TestFixture
      35             : {
      36             : public:
      37           1 :     void wrt_file()
      38             :     {
      39             :         FileBase::RC err;
      40             : 
      41             :         //create a tempfile
      42           1 :         rtl::OUString aTmpFile;
      43           1 :         err = FileBase::createTempFile(NULL, NULL, &aTmpFile);
      44           1 :         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           1 :         File tmp_file(aTmpFile);
      48           1 :         err = tmp_file.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create);
      49             : 
      50           1 :         rtl::OString sErrorMsg = "Expected that '";
      51           1 :         sErrorMsg += rtl::OUStringToOString(aTmpFile, RTL_TEXTENCODING_ASCII_US);
      52           1 :         sErrorMsg += "' would exist!";
      53           1 :         CPPUNIT_ASSERT_MESSAGE(sErrorMsg.getStr(), err == FileBase::E_EXIST);
      54             : 
      55             :         char buffer[1];
      56           1 :         sal_uInt64 written = 0;
      57           1 :         err = tmp_file.write((void*)buffer, sizeof(buffer), written);
      58           2 :         CPPUNIT_ASSERT_MESSAGE("write on unconnected file should fail",
      59           1 :             err != osl::FileBase::E_None && written == 0);
      60             : 
      61           1 :         err = tmp_file.sync();
      62           1 :         CPPUNIT_ASSERT_MESSAGE("sync on unconnected file should fail", err != FileBase::E_None);
      63           1 :         err = tmp_file.close();
      64           1 :         CPPUNIT_ASSERT_MESSAGE("close on unconnected file should fail", err != FileBase::E_None);
      65             : 
      66           1 :         err = ::osl::File::remove(aTmpFile);
      67           1 :         CPPUNIT_ASSERT_MESSAGE("temp file should have existed", err == FileBase::E_None);
      68           1 :     }
      69             : 
      70           2 :     CPPUNIT_TEST_SUITE(test_osl_writeFile);
      71           1 :     CPPUNIT_TEST(wrt_file);
      72           2 :     CPPUNIT_TEST_SUITE_END();
      73             : };
      74             : 
      75             : //#####################################
      76             : // register test suites
      77           1 : CPPUNIT_TEST_SUITE_REGISTRATION(test_osl_writeFile);
      78             : 
      79           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      80             : 
      81             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10