1 /*
2     oscartestbase.cpp - OSCAR Testlib base
3 
4     Copyright (c) 2006 by Brian Smith <linuxfood@linuxfood.net>
5 
6     Kopete    (c) 2002-2006 by the Kopete developers  <kopete-devel@kde.org>
7 
8     *************************************************************************
9     *                                                                       *
10     * This library is free software; you can redistribute it and/or         *
11     * modify it under the terms of the GNU Lesser General Public            *
12     * License as published by the Free Software Foundation; either          *
13     * version 2 of the License, or (at your option) any later version.      *
14     *                                                                       *
15     *************************************************************************
16 */
17 
18 #include "oscartestbase.h"
19 #include <QFile>
20 #include <QByteArray>
21 #include <QDir>
22 #include "buffer.h"
23 
OscarTestBase()24 OscarTestBase::OscarTestBase()
25     : m_data( 0 )
26 {
27 }
28 
~OscarTestBase()29 OscarTestBase::~OscarTestBase()
30 {
31 	delete m_data;
32 }
33 
setPath(const QString & path)34 void OscarTestBase::setPath( const QString& path )
35 {
36 	m_dataDir = path;
37 }
38 
loadFile(const QString & file)39 bool OscarTestBase::loadFile(const QString& file)
40 {
41 	if ( ! QFile::exists(m_dataDir + QDir::separator() + file) )
42 		return false;
43 
44 	QFile datFile(m_dataDir + QDir::separator() + file);
45 	if (! datFile.open(QIODevice::ReadOnly))
46 		return false;
47 	if ( m_data != NULL )
48 	{
49 		delete m_data;
50 		m_data = NULL; //Safety
51 	}
52 	m_data = new Buffer(datFile.readAll());
53 	datFile.close();
54 	if (m_data->length() == 0)
55 		return false; //unless it's an empty file, we must have failed
56 	return true;
57 }
58 
59