Old Blog Entries

When I upgraded this site to Drupal, I added some blog entries which I’d done on my laptop whilst on holiday in Inverness, but not uploaded to the web:

    * Layouts in Qt
    * CppUnit: Some More Discoveries
    * CppUnit Starting Out

All entries prior to this starting from the one just entitled Amos on 8/4/2005 were from my previous blog (also at this site address) which was Pivot based.

I’ve just been looking at the Wayback Machine hosted at the Internet Archive, and found the entries for the previous blog which I had encoded by hand, so I’m going to add these in too, they’re dated between 18/2/04 and 30/9/04 but have no titles so I’ll have to make these up as I go.

Adding them now.

Layouts in Qt

I think I’ve finally cracked the layout mechanism in Qt Designer, it isn’t straightforward and intuitive to get set up by any means. Basically once you have various bits you want to layout you need to start looking at their sizing policy, geometry and various other bits. You also seem to need to make liberal use of the stretcher things. You basically seem to need to nest the layouts one inside another if you you want buttons for instance in a column always a certain distance apart then you have to put fixed height spacers between each one, then select all of the buttons and spacers (not just clicking and dragging a box around them) then select layout vertically. If you then want them to remain reasonably constant in size as the width of the window decreases you need more horizontal spacers of a fixed width then a horizontal layout.

At this point you discover that you left the buttons horizontal size policy set to expanding which means they try to expand to take up all of the available room (if you put this current layout box in a horizontal layout with another expanding layout box they both expand to take up half of the width, the buttons stretching to fill the space). If you decide that you meant that the buttons should stay a reasonable size you need to go back and change their horizontal size policy, unfortunately this seems to involve breaking all of the nested layouts they were part of, changing the size policies an then re-instigating each layout box.

Maybe I’m doing it wrong but there must be a quicker way than this, should the layout boxes not inherit from the current settings rather than causing the affected items to behave unpredictably. Maybe this is a known issue but as I’m in Inverness in a holiday home I can’t check at the moment.

Listening: Manu Chao – Clandestino
Reading Book: Sergei Lukyanenko – The Night Watch
Reading Magazine: Linux Journal (Issue 172 – August 2008)
Drinking: Famous Grouse (in about 5 minutes time)

And so to bed.

CppUnit: Some More Discoveries

Tuesday 12th of August 2008 21:24

One thing I don’t think I mentioned in the last post is that in the ClassNameTest.cpp file we need to register the test suite using a macro:

[code]
    CPPUNIT_TEST_SUITE_REGISTRATION( ClassNameTest );
[/code]

which registers the test suite so that it will be run.

The assertions which are possible include (lifted directly from the api documentation at the CppUnit sourceforge page):

CPPUNIT_ASSERT(condition)
Aserts that condition is true.

CPPUNIT_ASSERT_MESSAGE(message, condition)
Asert condition is true, and display message on failure.

CPPUNIT_FAIL(message)
Fails with the message.

CPPUNIT_ASSERT_EQUAL(expected, actual)
Checks that both values are equal.

CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual)
As above but fails with the message.

CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta)
Checks that expected is within delta of actual (delta should actually be epsilon!)

CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(message, expected, actual, delta)
As above but fails with message.

CPPUNIT_ASSERT_THROW(expression, ExceptionType)
Asserts that the given expression throws an exception of the type given.

CPPUNIT_ASSERT_THROW_MESSAGE(message, expression, ExceptionType)
As above but with a message on failure.

CPPUNIT_ASSERT_NO_THROW(expression)
This is the opposite of the above the expression does NOT throw an exception.

CPPUNIT_ASSERT_NO_THROW_MESSAGE(message, expression)
If it does throw an exception then we fail with the given message.

CPPUNIT_ASSERT_ASSERTION_FAIL(assertion)
Assert that a CPPUNIT assertion will fail.

CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE(message, assertion)
As above but with a message if the assertion passes.

CPPUNIT_ASSERT_ASSERTION_PASS(assertion)
Assert that a CPPUNIT assertion will pass.

CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE(message, assertion)
As above but displays he message of it fails.

I think there are more possible assertions as the CppUnit Cookbook uses a statement in setting up the tests which checks for a given exception type being thrown.

Enough for today.
 

CppUnit Starting Out

I’ve decided to try and keep a bit of a blog by writing it in Emacs on my laptop and then copying the resulting text over to the actual online Blog.

This evening I’ve finished going through the first part of the CppUnit simple tutorial, but I still need to get a better idea of what is entailed in using it, so I’ll have to try working through the Cookbook even though it starts with other Test versions than the one in the Tutorial.

Maybe I should work through the cookbook and then write my own tutorial, using the development of my canvas class as a result then use the resulting tutorial as part of my write up for the final project. Plus I need to get CppUnit working on Windows so that I can do all of my testing there.

The basic tutorial covers setting up a Test Suite and demonstrates the use of CPPUNIT_TEST and CPPUNIT_TEST_EXCEPTION. But in the actual test section, it only uses CPPUNIT_ASSERT.

These seem to work as follows, we have files ClassName.h,
ClassName.cpp, ClassNameTest.h, ClassNameTest.cpp and ClassNameApp.cpp (plus I guess any user defined classes we need for the tests).

In the “Private” section of the class in the ClassNameTest.h file we put:

[code]
CPPUNIT_TEST_SUITE( ClassNameTest );
CPPUNIT_TEST( testFunctionName1 );
CPPUNIT_TEST( testFunctionName2 );
CPPUNIT_TEST_EXCEPTION( testFunctionName3, someException );
CPPUNIT_TEST_SUITE_END();
[/code]

someException is an exception which inherits from runtime_error defined in . Then in the “Public” section of the class we declare:

[code]
void testFunctionname1();
void testFunctionname2();
[/code]

We then go to the ClassNameTest.cpp file and define each of these two functions, eg:

[code]
void ClassNameTest::testFunctionName1()
{
Set up any variables
Do whatever needs doing
CPPUNIT_ASSERT( Some boolean test )
}

void ClassNameTest::testFunctionName2()
{
Set up any variables
Do whatever needs doing
CPPUNIT_ASSERT( Some boolean test )
}

void ClassNameTest::testFunctionNam31()
{
Set up any variables
Do whatever needs doing which should trigger the
exception defined above otherwise the test suite will fail due
to an expected exception not being thrown.
}
[/code]

We either define the exception ourselves or use a runtime_error which is predefined.

Setting up the project requires a few steps.

Create a configure.in file containing:

[code]
dnl Process this file with autoconf to produce a configure script
AC_INIT(Makefile.am)
AM_INIT_AUTOMAKE(*classname?*,0.1)
AM_PATH_CPPUNIT(1.9.6)
AC_PROG_CXX
AC_PROG_CC
AC_PROG_INSTALL
AC_OUTPUT(Makefile)
[/code]

and a Makefile.am containing:

[code]
# Rules for the test code (use ‘make check’ to execute)
TESTS = ExecutableName
check_PROGRAMS = $(TESTS)
ExecutableName_SOURCES = List of all of the source files to be compiled in
ExecutableName_CXXFLAGS = $(CPPUNIT_CFLAGS)
ExecutableName_LDFLAGS = $(CPPUNIT_LIBS) -ldl
[/code]

We need a ClassNameApp.cpp file containing:

[code]
#include
#include
#include

int main(int argc, char* argv[])
{
// Get the top level suite from the registry
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
CppUnit::TextUi::TestRunner runner;
runner.addTest( suite );

runner.setOutputter(new CppUnit::CompilerOutputter( &runner.result(), std::cerr) );
bool wasSuccessful = runner.run();

return wasSuccessful ? 0 : 1;
}
[/code]

We need to do the following at the command line too:

[code]
$ touch Names of any source files we haven’t created yet.
$ aclocal -I /usr/local/share/aclocal
$ autoconf
$ automake -a
$ touch NEWS README AUTHORS ChangeLog (this stops automake complaining)
$ automake
$ ./configure
$ make check
[/code]

make check builds and runs the test application for us, and this is what we have to run each time we wish to run the tests. Most of the above is based on the Simple Tutorial for CPPUNIT available at:

http//cppunit.sourceforge.net/doc/1.11.6/money_example.html

Bed now.

One Assignment Down

Hooray! I’ve finished one assignment (the website/automated telephone one for HCI), two more to go.

I did some concept mapping last night but my heart wasn’t really in it. I’ll carry on tonight I think and see how far I get. Then I actually have to go to my HCI lecture tomorrow, which I don’t look forward to.

Moodle day tomorrow, I’ve got two more teachers’ classes to add (I need to write a script to re-enable their passwords if they ae disabled and in that class), then it’s time to work out whether I should put the data from SIMS.net into a MySQL Database or store it as a flat file.

Then I really have to get cracking on my project work on Thursday (if I can’t sort out the bizarre rotation problem then I’ll have to cut down to just cardinal directions). I think I need to compile a static version of Qt to let me do the project. Once I’ve cracked the movement issues I’l be able to reuse it in the other one.

This afternoon I’ve updated some of the components of LispBox 0.7 to newer ones. Emacs 23.0.50.0 (I think) CLisp 2.44 SLIME (24-4-08 edition) I would also like to try and use SBCL as my Lisp in here but I can’t quite get it working. I don’t want to lose my other emacs settings so I need to work out how to reset the HOME variable so that it points to a local .emacs file. I’ll post some instructions if I manage to work out what I’m doing.

I’ve agreed to take part in the Manchester to Blackpool Charity Bike Ride in July (how stupid am I) for Christies. It’s only 60 miles so I’ve spent the last week puffing and panting up hills, luckily I’ve got another 2 1/2 months until we actually do it so I should manage without keeling over dead of a heart-attack. We’re going to be riding as Team Janice in memory of Janice who died last May (23d I think), I’ll try and add a static page with training to this site so I can keep track of how much I’m doing (or not). Off now.

(Post Script: Page added for training log )

Pointy Birds

Last week, and last night we covered C++ pointers, basically it seems to boil down to the following bits. A pointer to an integer object which contains the value 1, can be written as:

int* fred = new int( 1 );

which can be split into three parts:

a. int* fred which declares fred as a pointer to an integer.
b. fred = new int; which allocates enough memory to hold the integer to which fred points
c. *fred = 1; which puts the value of 1 into the object to which fred points ( or *fred )

Pointers can be passed to and returned from functions ( and also need to be deleted in certain circumstances which didn’t get explained), if a pointer is passed into a function then, the object to which it points can be altered, and the ampersand used when we pass by reference is also an address, thereby providing us with a pointer to something.
 

Programming Course

All afternoon on Sunday and from 2.30 until 11pm yesterday I was working on two C++ programs for my course. I went to college this evening only to find the lecture cancelled because the lecturer was off ill. What a pain that was, basically I could have taken my time and handed them in next week and all would have been fine.

It does mean that I’ll be able to rework part of the first program which traps and deals with errors in the input(this is only a first year programming course so we haven’t got on to anything complicated like exception handling yet). But its still a pain having worked so hard on it in such a short space of time to suddenly find that it didn’t have to be done until next week after all.

I have handed in the other Assignment on Access.

Night, night.
 

Access 2003 Database

I spent all day yesterday completing an Assignment for my course using Access 2003, what a pain it is to use! I’ve used most of the other common elements of Microsoft Office on a fairly regular basis, but until I started this module I’d had no reason to try Access.

The Help files are awful, they tell you next to nothing about how to do stuff its all “Function X has failed to work because Gizmo Y is not Z, please make Y have Z before trying to use X” (ok that may be a bit of an exaggeration but you know what I mean). Generating Reports was a pain, there doesn’t seem to be a way of saving the Report in the format its generated in, every time you open what appears to be a saved Report it regenerates the contents on the fly wiping anything you’d tried to save.

Trying to make anything but the simplest of Reports is a nightmare, the formatting (lines etc) are awful working out whether the data you’re going to show is Left Aligned, Centered or Right Aligned isn’t obvious. Text Boxes and Labels which are LINKED aren’t aligned properly! It reminded me of all of the bad things about early versions of Windows and other systems like the Amiga, where simple things were hard to do, for god’s sake how hard is it to draw a horizontal line?

Anyway rant over, today I’ve got another asignment to do, this ones in C++ and I’m using Visual C++.net 2003 version which is an example of how to do something reasonably right (it’s a damn site more intuitive to use than Access).

Time to go, as I need to get cracking, its due in on Tuesday so it might be worth actually starting it.

Cheers.

Downloading MinGW

Well I’ve just been looking around on the net to see if I can find a decent IDE and I’m in the process of downloading the MinGW Developer Studio (23 Meg over dialup so a bit of a wait in store) which looks alright but I’ll have to wait and see. Am very tired, K’s at School still, its their Open Evening so she’ll be gone for a good while yet, its my turn next Thursday.

At work yesterday I had yet another set-back in trying to get the “Classroom in a box” working with Maths Alive, our ICT technician supplied me with the user name and password to access the site but it refused to work. So we’re still waiting 6 months after they arrived to use the laptops with a class. If I can get them working before next week, then I’ll have some out with the kids during Open Evening. But if there’s nothing to run on them then there’s no point. They did however come and measure my room in preparation for installing the Interactive Whiteboard and Projector.

I think I’ll have a play with C++ again later to get my eye in before I start at the Institute next week, and to have a go at this MinGW DS thing to see if its any good. I went to PC World on the way home tonight, they’re selling MS Visual C++.NET 2003 version for £99.99, but if you buy the Deluxe Learning Edition (advertised as containing the full version of Visual C++.NET) which is sold with a book, it’ll only cost you £86.95, bizarre or what.

Its my busy day tomorrow, I teach all day, and finish off with 8S, who so far don’t seem too bad. If I remember right I’m doing constructions with them so that’ll be fun, and I’ve threatened to keep behind any of them who don’t come properly equipped.

Anyway I’m going now as its time for me to sort out my tea.
 

Playing with Dasher

I went to the Institute last night for my induction. The first session of the evening was good as I finally got some details about the Modules I’m doing. The first one’s called Computer Environments, which seems to be a basic course about computers, and how they work. Whilst the second is called Programming and Design I, which seems to be a basic course in C++. Next semester I’m going to be doing the second part of the Programming and Design course along with one on Information Systems.

I spoke to a couple of the other blokes who are doing the same modules as me, they seemed pleasant enough though it’s early days yet. They gave us a couple of handouts to do with the course, which gives a list of Indicative Reading for each module, but the books listed may be out of date. Anyway the modules begin properly on Tuesday evening, next week so I’ll have more of an idea once we’re actually underway. After the initial Departmental Induction it was time for a visit to the library and resource centre where we all got logon details for the network and email addresses.

Finally we had a presentation by the Dean of Students which was alright but nothing I hadn’t heard before, basically she talked about all of the things which it might be useful to know as a new student in Bolton. The most relevant fact to me was probably the fact that the Institute is going to be renamed in the next few months as the University of Bolton unsurprisingly enough.

Most of the text for this entry was entered using Dasher, a bizarrely addictive text entry system, if you haven’t tried it yet give it a go, I’m trying to work out if there’s some way of using it in conjunction with the Interactive Whiteboard I’m due to get in my room at work, but I’m not sure how useful it’ll be.

I’m going to stop playing with C#, in the very near future I think, even though I really quite like it so that I can concentrate on C++, which is probably going to end up being my language of choice. Now I just need to find a non-M$ development environment to use on Windows and I’ll be laughing. At least if its as good as KDevelop or #Develop in terms of code completion etc.