xref: /trunk/main/sal/qa/osl/file/test_cpy_wrt_file.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
30 
31 #include <testshl/simpleheader.hxx>
32 #include <osl/file.hxx>
33 #include <osl/thread.h>
34 #include <rtl/ustring.hxx>
35 
36 using namespace osl;
37 using namespace rtl;
38 
39 //########################################
40 #ifdef UNX
41 #   define COPY_SOURCE_PATH "/home/tr109510/ucbhelper.cxx"
42 #   define COPY_DEST_PATH "/mnt/mercury08/ucbhelper.cxx"
43 #else /* if WNT */
44 #   define COPY_SOURCE_PATH "d:\\msvcr70.dll"
45 #   define COPY_DEST_PATH "x:\\tra\\msvcr70.dll"
46 #endif
47 
48 class test_osl_copyFile : public CppUnit::TestFixture
49 {
50 public:
51     void cp_file()
52     {
53 		rtl::OUString src_url;
54 		FileBase::getFileURLFromSystemPath(rtl::OUString::createFromAscii(COPY_SOURCE_PATH), src_url);
55 
56 		rtl::OUString dest_url;
57         FileBase::getFileURLFromSystemPath(rtl::OUString::createFromAscii(COPY_DEST_PATH), dest_url);
58 
59 		FileBase::RC err = File::copy(src_url, dest_url);
60 		CPPUNIT_ASSERT_MESSAGE("Copy didn't recognized disk full", err != FileBase::E_None);
61     }
62 
63     CPPUNIT_TEST_SUITE(test_osl_copyFile);
64     CPPUNIT_TEST(cp_file);
65     CPPUNIT_TEST_SUITE_END();
66 };
67 
68 //########################################
69 #ifdef UNX
70 #   define WRITE_DEST_PATH "/mnt/mercury08/muell.tmp"
71 #else /* if WNT */
72 #   define WRITE_DEST_PATH "d:\\tmp_data.tmp"
73 #endif
74 
75 class test_osl_writeFile : public CppUnit::TestFixture
76 {
77 public:
78     void wrt_file()
79     {
80 		rtl::OUString dest_url;
81 		FileBase::getFileURLFromSystemPath(rtl::OUString::createFromAscii(WRITE_DEST_PATH), dest_url);
82 
83         File tmp_file(dest_url);
84 		rtl::OUString suErrorMsg = rtl::OUString::createFromAscii("File creation failed: ")+ dest_url;
85 		FileBase::RC err = tmp_file.open(osl_File_OpenFlag_Write | osl_File_OpenFlag_Create);
86 
87 		CPPUNIT_ASSERT_MESSAGE( suErrorMsg, err == FileBase::E_None || err == FileBase::E_EXIST );
88 
89 		char buffer[50000];
90 		sal_uInt64 written = 0;
91 		err = tmp_file.write((void*)buffer, sizeof(buffer), written);
92 
93         err = tmp_file.sync();
94 
95 		CPPUNIT_ASSERT_MESSAGE("Write didn't recognized disk full", err != FileBase::E_None);
96 
97 		tmp_file.close();
98     }
99 
100     CPPUNIT_TEST_SUITE(test_osl_writeFile);
101     CPPUNIT_TEST(wrt_file);
102     CPPUNIT_TEST_SUITE_END();
103 };
104 
105 //#####################################
106 // register test suites
107 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_osl_writeFile, "test_osl_writeFile");
108 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test_osl_copyFile,  "test_osl_copyFile");
109 
110 NOADDITIONAL;
111 
112