Changed package description to indicate Helsinki only
authorMax Waterman <david.waterman@nokia.com>
Mon, 19 Apr 2010 05:37:41 +0000 (08:37 +0300)
committerMax Waterman <david.waterman@nokia.com>
Mon, 19 Apr 2010 09:09:14 +0000 (12:09 +0300)
Changed 'fake gps' button from two actions to a single toggle one
Changed 'show messages' button from two actions to a single toggle one
Fixed core dump in gpscontroller caused by deleting the fakelocation

19 files changed:
zouba/debian/changelog
zouba/debian/control
zouba/debian/files
zouba/src/gpscontroller.cpp
zouba/src/gpscontroller_p.cpp
zouba/src/location.cpp
zouba/src/location_p.cpp
zouba/src/route.cpp
zouba/src/ui.cpp
zouba/src/ui.h
zouba/tests/testSummary [new file with mode: 0755]
zouba/tests/tests.pro
zouba/tests/ut_gpscontroller/Makefile
zouba/tests/ut_gpscontroller/ut_gpscontroller
zouba/tests/ut_gpscontroller/ut_gpscontroller.cpp
zouba/tests/ut_gpscontroller/ut_gpscontroller.h
zouba/tests/ut_gpscontroller/ut_gpscontroller.pro
zouba/tests/ut_location/ut_location.pro
zouba/tests/ut_route/ut_route.pro

index ddef629..c694d2c 100644 (file)
@@ -1,3 +1,11 @@
+zouba (0.5) unstable; urgency=low
+
+  * Changed package description
+  * Changed 'fakegps' button from two actions to a single toggle one
+  * Fixed core dump in gpscontroller caused by deleting the fakelocation
+
+ -- Max Waterman <davidmaxwaterman@fastmail.co.uk>  Mon, 19 Apr 2010 11:18:00 +0200
+
 zouba (0.4) unstable; urgency=low
 
   * Fix for routes with bus changes (only displays first bus)
index 9951d43..bb9a57f 100644 (file)
@@ -9,7 +9,7 @@ Homepage:
 Package: zouba
 Architecture: armel
 Depends: ${shlibs:Depends}, ${misc:Depends}
-Description: Tells you which bus is next.
+Description: Tells you which bus is next (in Helsinki area).
  Allows you to easily find how to get the bus home. Uses HSL Journey Planner API <http://developer.reittiopas.fi/pages/en/home.php>. Uses GPS for current location. Uses Qt and QtMobility.
 # XB-Maemo-Icon-26 field contains the application icon file encoded in
 # base64. This is the icon that is shown in the Application Manager,
index 45b11ce..b584481 100644 (file)
@@ -1 +1 @@
-zouba_0.3_armel.deb user/navigation extra
+zouba_0.5_armel.deb user/navigation extra
index e924da5..e4de9b4 100644 (file)
@@ -35,12 +35,13 @@ void GpsController::getGps()
 void GpsController::useLiveGps()
 {
   q->setUseFakeLocation( false );
-  q->setCurrentLocation(0);
+  q->setCurrentLocation( new Location( "livegps" ) );
   q->startGps();
 }
 
 void GpsController::useFakeGps( Location *fakeLocation )
 {
+  qDebug() << "using fake gps (" << fakeLocation->label() << ")";
   q->stopGps();
   q->setUseFakeLocation( true );
   q->setCurrentLocation( fakeLocation );
index 6c6951e..c654146 100644 (file)
@@ -60,7 +60,10 @@ Location *GpsControllerPrivate::currentLocation()
 
 void GpsControllerPrivate::setCurrentLocation( Location *location )
 {
-  delete m_currentLocation;
+  if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
+    delete m_currentLocation;
+    m_currentLocation=0;
+  }
   m_currentLocation = location;
 }
 
@@ -71,14 +74,19 @@ bool GpsControllerPrivate::useFakeLocation()
 
 void GpsControllerPrivate::setUseFakeLocation( bool useFake )
 {
+  // delete previous GPS if it was live and we're switching to fake
+  if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
+    delete m_currentLocation;
+    m_currentLocation = 0;
+  }
   m_useFakeLocation = useFake;
 }
 
 void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
 {
-  if ( !m_useFakeLocation ) {
+  if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
     delete m_currentLocation;
-    m_currentLocation = new Location( positionInfo );
   }
+  m_currentLocation = new Location( positionInfo, "livegps" );
 }
 
index 4a4a1a7..90f71c4 100644 (file)
@@ -44,6 +44,7 @@ Location::Location( const QGeoPositionInfo &positionInfo, const QString &label )
   q( new LocationPrivate( label ) ),
   manager(0)
 {
+  qDebug() << "Location::Location( QGeoPositionInfo, label=" << label << " )";
   qreal latitude = positionInfo.coordinate().latitude();
   qreal longitude = positionInfo.coordinate().longitude();
 
@@ -62,6 +63,7 @@ Location::Location( const Location &from ) :
   q( new LocationPrivate( from.label() ) ),
   manager(0)
 {
+  qDebug() << "Location::Location( const Location [" << from.label() << "] )";
   q->setAddress( from.address() );
   q->setX( from.x() );
   q->setY( from.y() );
@@ -76,6 +78,7 @@ Location::Location( const QString &label ) :
   q( new LocationPrivate( label ) ),
   manager( new QNetworkAccessManager(this) )
 {
+  qDebug() << "Location::Location( const QString &label=" << label << " )";
   connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
 }
 
@@ -89,18 +92,20 @@ Location::~Location()
 
 Location &Location::operator=( const Location &from )
 {
+  qDebug() << "Location::Location( const Location &from )";
   q = new LocationPrivate( from.label() );
   q->setAddress( from.address() );
   q->setX( from.x() );
   q->setY( from.y() );
   q->setValid( from.isValid() );
+
   if ( from.manager != 0 ) {
     manager = new QNetworkAccessManager(this);
     connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
   } else {
     manager = 0;
   }
-  
+
   return *this;
 }
 
@@ -223,7 +228,7 @@ void Location::KKJlola_to_WGS84lola(double kkjlo, double kkjla, double *outLongi
 
 
 // Function:  WGS84lalo_to_KKJlalo
-void Location::WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude) 
+void Location::WGS84lola_to_KKJlola(double longitude, double latitude, double *outLongitude, double *outLatitude)
 {
   double dLa = radians(-0.124766E+01 + 0.269941E+00 * latitude + -0.191342E+00 * longitude + -0.356086E-02 * latitude * latitude + 0.122353E-02 * latitude * longitude + 0.335456E-03 * longitude * longitude) / 3600.0;
   double dLo = radians(0.286008E+02 + -0.114139E+01 * latitude + 0.581329E+00 * longitude + 0.152376E-01 * latitude * latitude + -0.118166E-01 * latitude * longitude + -0.826201E-03 * longitude * longitude) / 3600.0;
@@ -234,7 +239,7 @@ void Location::WGS84lola_to_KKJlola(double longitude, double latitude, double *o
 
 
 // Function:  KKJlalo_to_KKJxy
-void Location::KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY) 
+void Location::KKJlola_to_KKJxy(double lon, double lat, int zoneNumber, KKJ *outX, KKJ *outY)
 {
   // Hayford ellipsoid
   double a = 6378388.0;
index b915be2..383622d 100644 (file)
@@ -25,6 +25,11 @@ LocationPrivate::LocationPrivate( const QString &label ) :
 
 LocationPrivate::~LocationPrivate()
 {
+  m_label="deleted";
+  m_address="";
+  m_x="";
+  m_y="";
+  m_valid=false;
 }
 
 void LocationPrivate::parseReply( const QByteArray &reply )
index 4eaa5c5..aefc185 100644 (file)
@@ -62,7 +62,7 @@ void Route::replyFinished( QNetworkReply * reply )
 
 void Route::setFromLocation( Location *location )
 {
-  qDebug() << "setting new From location";
+  qDebug() << "setting new From location (" << location->label() << ")";
 
   if ( location && location->isValid() ) {
     qDebug() << "From is valid";
@@ -75,6 +75,7 @@ void Route::setFromLocation( Location *location )
     }
   } else {
     qDebug() << "ERROR:From is not valid";
+    qDebug() << "location=" << location;
   }
 }
 
@@ -85,7 +86,7 @@ Location *Route::fromLocation() const
 
 void Route::setToLocation( Location *location )
 {
-  qDebug() << "setting new To location";
+  qDebug() << "setting new To location (" << location->label() << ")";
 
   if ( location && location->isValid() ) {
     qDebug() << "To is valid";
index 98aac09..7660ee0 100644 (file)
@@ -23,8 +23,16 @@ MessageTable *Ui::messageTable = 0;
 Ui::Ui() :
   centralWidget(0),
   destinationButtons(0),
-  routeTable(0)
+  routeTable(0),
+  usingFakeGps( false ),
+  messagesShown( false ),
+  fakeLocation()
 {
+  Locations *locations = Locations::instance();
+  Location *workLocation = locations->location( "work" );
+  fakeLocation = new Location();
+  *fakeLocation = *workLocation;
+  fakeLocation->setLabel( "fakegps" );
 }
 
 Ui::~Ui()
@@ -38,14 +46,12 @@ void Ui::setupUi( QMainWindow *mainWindow )
 
   QAction *setHomeAddressAction = new QAction("Set home address", this);
   QAction *setWorkAddressAction = new QAction("Set work address", this);
-  hideMessagesAction   = new QAction("Hide messages", this);
-  showMessagesAction   = new QAction("Show messages", this);
-  useFakeGpsAction   = new QAction("Use fake GPS", this);
-  useLiveGpsAction   = new QAction("Use live GPS", this);
+  toggleMessagesAction = new QAction("Show messages", this);
+  toggleFakeGpsAction  = new QAction("Use fake GPS", this);
   menu->addAction(setHomeAddressAction);
   menu->addAction(setWorkAddressAction);
-  menu->addAction(showMessagesAction);
-  menu->addAction(useFakeGpsAction);
+  menu->addAction(toggleMessagesAction);
+  menu->addAction(toggleFakeGpsAction);
 
   connect(
       setHomeAddressAction, SIGNAL(triggered()),
@@ -56,20 +62,12 @@ void Ui::setupUi( QMainWindow *mainWindow )
       this, SLOT(setWorkAddress())
       );
   connect(
-      hideMessagesAction, SIGNAL(triggered()),
-      this, SLOT(hideMessages())
-      );
-  connect(
-      showMessagesAction, SIGNAL(triggered()),
-      this, SLOT(showMessages())
-      );
-  connect(
-      useFakeGpsAction, SIGNAL(triggered()),
-      this, SLOT(useFakeGps())
+      toggleMessagesAction, SIGNAL(triggered()),
+      this, SLOT(toggleMessages())
       );
   connect(
-      useLiveGpsAction, SIGNAL(triggered()),
-      this, SLOT(useLiveGps())
+      toggleFakeGpsAction, SIGNAL(triggered()),
+      this, SLOT(toggleFakeGps())
       );
 
   centralWidget = new QWidget( mainWindow );
@@ -127,36 +125,50 @@ void Ui::setWorkAddress()
   setAddress( "work" );
 }
 
+void Ui::toggleMessages()
+{
+  messagesShown = !messagesShown;
+
+  if ( messagesShown ) {
+    showMessages();
+  } else {
+    hideMessages();
+  }
+}
+
 void Ui::hideMessages()
 {
   messageTable->hide();
-  menu->removeAction( hideMessagesAction );
-  menu->addAction( showMessagesAction );
+  toggleMessagesAction->setText( "Show messages" );
 }
 
 void Ui::showMessages()
 {
   messageTable->show();
-  menu->removeAction( showMessagesAction );
-  menu->addAction( hideMessagesAction );
+  toggleMessagesAction->setText( "Hide messages" );
 }
 
-void Ui::useFakeGps()
+void Ui::toggleFakeGps()
 {
-  // really want a dialog here
-  Locations *locations = Locations::instance();
-  Location *fakeLocation = locations->location( "work" );
+  usingFakeGps = !usingFakeGps;
 
+  if ( usingFakeGps ) {
+    useFakeGps();
+  } else {
+    useLiveGps();
+  }
+}
+
+void Ui::useFakeGps()
+{
   emit fakeGpsPressed( fakeLocation );
-  menu->removeAction( useFakeGpsAction );
-  menu->addAction( useLiveGpsAction );
+  toggleFakeGpsAction->setText( "Use Live GPS" );
 }
 
 void Ui::useLiveGps()
 {
   emit liveGpsPressed();
-  menu->removeAction( useLiveGpsAction );
-  menu->addAction( useFakeGpsAction );
+  toggleFakeGpsAction->setText( "Use Fake GPS" );
 }
 
 void Ui::setAddress( const QString &label )
@@ -174,8 +186,6 @@ void Ui::setAddress( const QString &label )
      &ok
      );
 
-  qDebug() << "ok=" << ok;
-
   if ( ok ) {
     qDebug() << "new address" << address;
     Locations *locations = Locations::instance();
index 787eb63..ecaee4f 100644 (file)
@@ -45,10 +45,12 @@ public:
   QHBoxLayout *mainLayout;
   QVBoxLayout *buttonLayout;
   QMenu       *menu;
-  QAction     *hideMessagesAction;
-  QAction     *showMessagesAction;
-  QAction     *useFakeGpsAction;
+  QAction     *toggleMessagesAction;
+  QAction     *toggleFakeGpsAction;
   QAction     *useLiveGpsAction;
+  bool        usingFakeGps;
+  bool        messagesShown;
+  Location    *fakeLocation;
 
 Q_SIGNALS:
   void homeAddressChanged( QString address );
@@ -59,12 +61,14 @@ Q_SIGNALS:
 private Q_SLOTS:
   void setHomeAddress();
   void setWorkAddress();
-  void hideMessages();
-  void showMessages();
-  void useFakeGps();
-  void useLiveGps();
+  void toggleMessages();
+  void toggleFakeGps();
 
 private:
+  void useFakeGps();
+  void useLiveGps();
+  void hideMessages();
+  void showMessages();
   void setAddress( const QString &label );
 };
 #endif //UI_H
diff --git a/zouba/tests/testSummary b/zouba/tests/testSummary
new file mode 100755 (executable)
index 0000000..3766d93
--- /dev/null
@@ -0,0 +1,310 @@
+#! /usr/bin/perl
+require 5.008_004; # we need at least Perl version v5.8.4
+$ENV{MALLOC_CHECK_} = 2;
+
+use Term::ANSIColor;
+
+my $startTime = time();
+
+my %opts = (
+    "a" => 0, # all directories, irrespective of if they're in tests.pro
+    "r" => 0, # don't reverse sort
+    "s" => "D", # by default, sort by directory name
+    "j" => 1, # one make job at a time by default
+);
+
+for ( my $argNo=0; $argNo<@ARGV; $argNo++ ) {
+    my $arg = $ARGV[ $argNo ];
+    if ( $arg eq "-h" ) {
+        print "usage: $0 [-a] [-s letter] [-r] [-j number] [-h]\n";
+        print "       -a            include all ut_*/ directories - default is just the ones in tests.pro\n";
+        print "       -s [DTPFS]    sort by column (Dirs, Tests, P(ass), F(ail), S(kipped)\n";
+        print "       -r            reverse sort\n";
+        print "       -j <number>   use <number> make jobs. Default is 1\n";
+        print "       -h            this help\n";
+        exit;
+    } elsif ( $arg eq "-r" ) {
+        $opts{ "r" } = 1;
+    } elsif ( $arg eq "-a" ) {
+        $opts{ "a" } = 1;
+    } elsif ( $arg eq "-s" ) {
+        $opts{ "s" } = $ARGV[ ++$argNo ];
+        if ( $opts{ "s" } !~ /[DTPFS]/ ) {
+            print "Unrecognised column identifier\n";
+            print "Must be one of [DTPFS] :\n";
+            print "  D = Dirs\n";
+            print "  T = Tests\n";
+            print "  P = Pass\n";
+            print "  F = Fail\n";
+            print "  S = Skipped\n";
+            exit(-1);
+        }
+    } elsif ( $arg eq "-j" ) {
+        my $jobs = $ARGV[ ++$argNo ];
+        # Test that the argument is a positive integer number
+        if ( $jobs * 1 eq $jobs && $jobs > 0 ) {
+            $opts{ "j" } = $jobs;
+        }
+    }
+}
+
+# some globals to help sort be faster
+$sortCol = $opts{ "s" };
+$sortIsNumeric = ( $sortCol =~ /[PFS]/ );
+$reverseSort = $opts{ "r" };
+# helper variable for the number of jobs
+$numJobs = $opts{ "j" };
+
+%maxLen = ();
+%segFault = ();
+
+my @rowHeaders = (
+    "D", # Dirs
+    "T", # Tests
+);
+my @rowData = (
+    "P", # Passed
+    "F", # Failed
+    "S", # Skipped
+);
+
+my @keys = ( @rowHeaders, @rowData );
+
+my %title = (
+    "D"=>"Dirs",
+    "T"=>"Tests",
+    "P"=>"P",
+    "F"=>"F",
+    "S"=>"S",
+);
+
+my $headerLabelFormat = "%-*s";
+my $headerDataFormat = "%*s";
+
+my $labelFormat = "%s%-*s%s%*s";
+my $dataFormat   = "%*s%s%*s%s";
+
+my %format = (
+  "D" => $labelFormat,
+  "T" => $labelFormat,
+  "P" => $dataFormat,
+  "F" => $dataFormat,
+  "S" => $dataFormat,
+);
+
+my %separator = (
+  "D" => " ",
+  "T" => " : ",
+  "P" => " ",
+  "F" => " ",
+  "S" => " ",
+);
+
+my %data = (
+);
+
+foreach $key ( @keys ) {
+    $maxLen{ $key } = length( $title{ key } );
+}
+
+# set the maximum length of the directories
+if ( $opts{ "a" } ) {
+    push @allDirs, <ut_*>;
+    push @allDirs, <ft_*>;
+    foreach ( @allDirs ) {
+        setMaxLen( "D", length( $_ ) );
+        $tested{ $_ } = 0;
+    }
+}
+
+# Compile first with possibly multiple jobs
+print "Compiling...";
+`make -j$numJobs -k > /dev/null 2>&1`;
+print "done.\nNow checking...\n";
+
+# then check with only one job so that the parsing succeeds
+open( MAKE, "make -k check 2>&1|" ) || die( "Could not run make:$!" );
+
+#$|=1;
+
+my $thisDir = "";
+while (<MAKE>) {
+    chomp;
+
+    if ( /Entering directory \`.*tests\/(\w+)\'/ ) {
+        $thisDir = $1;
+        print STDERR "Tests: $thisDir", ' 'x( $maxLen{ "D" }-length( $thisDir )+length("Tests: ") ), "\r";
+        $tested{ $thisDir } = 1;
+        push @allDirs, $thisDir if ( !grep( /^$thisDir$/, @allDirs ) );
+        setMaxLen( "D", length( $thisDir ) );
+    } elsif ( /Segmentation fault/ ) {
+        $segFault{ $thisDir } = $_;
+    } elsif ( /Start testing of (\w+)/ ) {
+        $thisTest = $1;
+        $data{ "T" }{ $thisDir } = $thisTest;
+        setMaxLen( "T", length( $data{ "T" }{ $thisDir } ) );
+    } elsif ( /^Totals: (\d+) passed, (\d+) failed, (\d+) skipped/ ) {
+        $data{ "P" }{ $thisDir } = "$1";
+        $data{ "F" }{ $thisDir } = "$2";
+        $data{ "S" }{ $thisDir } = "$3";
+        setMaxLen( "P", length( $data{ "P" }{ $thisDir } ) );
+        setMaxLen( "F", length( $data{ "F" }{ $thisDir } ) );
+        setMaxLen( "S", length( $data{ "S" }{ $thisDir } ) );
+    }
+}
+
+close( MAKE );
+
+print STDERR ' 'x( $maxLen{ "D" } + length( "Tests: " ) ), "\r";
+
+foreach $thisDir ( @allDirs ) {
+    if ( !defined( $data{ "P" }{ $thisDir } ) || $data{ "P" }{ $thisDir } eq "" ) {
+        $data{ "P" }{ $thisDir } = "0";
+        setMaxLen( "P", length( $data{ "P" }{ $thisDir } ) );
+    }
+    if ( !defined( $data{ "F" }{ $thisDir } ) ) {
+        $data{ "F" }{ $thisDir } = "0";
+        setMaxLen( "F", length( $data{ "F" }{ $thisDir } ) );
+    }
+    if ( !defined( $data{ "S" }{ $thisDir } ) ) {
+        $data{ "S" }{ $thisDir } = "0";
+        setMaxLen( "S", length( $data{ "S" }{ $thisDir } ) );
+    }
+
+    $data{ "D" }{ $thisDir } = $thisDir;
+}
+
+my ( $testsPassed, $testsNeedWork ) = ( 0, 0 );
+my $noTests = scalar( @allDirs );
+my $noDigits = ($noTests>0)?int( log( $noTests )/log( 10 ) )+1:1;
+
+my $header = sprintf( "%*s ", $noDigits, "" );
+
+foreach ( @rowHeaders ) {
+    $header .= sprintf( $headerLabelFormat.$separator{ $_ }, $maxLen{ $_ }, $title{ $_ } );
+}
+
+foreach ( @rowData ) {
+    $header .= sprintf( $headerDataFormat.$separator{ $_ }, $maxLen{ $_ }, $title{ $_ } );
+}
+
+my $headerLen = length( $header );
+
+my $headerColor = color( 'reset' );
+
+print "P = Pass, F = Fail, S = Skip\n";
+print $headerColor, "$header\n";
+print '-'x$headerLen, "\n";
+
+my $testNo = 1;
+
+foreach $thisDir ( sort byCol @allDirs ) {
+    my %colors = ();
+
+    foreach $key ( @keys ) {
+        $colors{ $key } = color( 'reset' );
+    }
+
+    if (
+        ( defined( $data{ "P" }{ $thisDir } ) && $data{ "P" }{ $thisDir } ne "0" ) &&
+        ( defined( $data{ "F" }{ $thisDir } ) && $data{ "F" }{ $thisDir } eq "0" ) &&
+        ( defined( $data{ "S" }{ $thisDir } ) && $data{ "S" }{ $thisDir } eq "0" ) &&
+        ( defined( $data{ "T" }{ $thisDir } ) && $data{ "T" }{ $thisDir } ne "" )
+    ) {
+        $testsPassed++;
+    } else {
+        $testsNeedWork++;
+    }
+
+    if ( defined( $data{ "P" }{ $thisDir } ) && $data{ "P" }{ $thisDir } eq "0" ) {
+        $colors{ "D" } .= color( 'reverse green' );
+        $colors{ "T" } .= color( 'reverse green' );
+        $colors{ "P" } .= color( 'reverse green' );
+    } else {
+        $colors{ "D" } .= color( 'green' );
+        $colors{ "T" } .= color( 'green' );
+        $colors{ "P" } .= color( 'green' );
+    }
+
+    if ( defined( $data{ "F" }{ $thisDir} ) && $data{ "F" }{ $thisDir } eq "0" ) {
+        $colors{ "F" } .= color( 'red' );
+    } else {
+        $colors{ "F" } .= color( 'reverse red' );
+    }
+
+    if ( defined( $data{ "S" }{ $thisDir } ) && $data{ "S" }{ $thisDir } eq "0" ) {
+        $colors{ "S" } .= color( 'blue' );
+    } else {
+        $colors{ "S" } .= color( 'reverse blue' );
+    }
+
+    if ( !defined( $data{ "T" }{ $thisDir } ) || $data{ "T" }{ $thisDir } eq "" || $segFault{ $thisDir } ) {
+        $colors{ "T" } .= color( 'reverse red' );
+    }
+
+    printf( "%*s ", $noDigits, $testNo );
+
+    foreach ( @rowHeaders ) {
+        my $thisData = $data{ $_ }{ $thisDir };
+        my $dataLength = length( $thisData );
+        my $spaceLength = $maxLen{ $_ }-$dataLength;
+
+        printf(
+            $format{ $_ }.$separator{ $_ },
+            $colors{ $_ }, $dataLength, $thisData,
+            color( 'reset' ), $spaceLength, "" );
+    }
+
+    foreach ( @rowData ) {
+        my $thisData = $data{ $_ }{ $thisDir };
+        my $dataLength = length( $thisData );
+        my $spaceLength = $maxLen{ $_ }-$dataLength;
+
+        printf(
+            $format{ $_ }.$separator{ $_ },
+            $spaceLength, "",
+            $colors{ $_ }, $dataLength, $thisData,
+            color( 'reset' ) );
+    }
+
+    printf( $headerColor."\n" );
+
+    $testNo++;
+}
+
+print '-'x$headerLen, "\n";
+print( "Tests with zero fails/skips : $testsPassed\n" );
+print( "Tests needing further work  : $testsNeedWork\n" );
+
+printf( "Elapsed time : %d seconds\n", time() - $startTime );
+
+sub setMaxLen
+{
+    my ( $test, $length ) = @_;
+
+    $maxLen{ $test } = $length if ( defined( $maxLen{ $test} ) && $length > $maxLen{ $test } );
+}
+
+sub byCol
+{
+    my $retVal = 0;
+
+    my $localA = $a;
+    my $localB = $b;
+
+    if ( $reverseSort ) {
+        my $tmp = $localA;
+        $localA = $localB;
+        $localB = $tmp;
+    }
+
+    if ( $sortIsNumeric ) {
+        # numeric comparison
+        $retVal = $data{ $sortCol }{ $localA } <=> $data{ $sortCol }{ $localB };
+    } else {
+        # string comparison
+        $retVal = $data{ $sortCol }{ $localA } cmp $data{ $sortCol }{ $localB };
+    }
+
+    return $retVal;
+}
index d8fd0f2..c81345e 100644 (file)
@@ -2,3 +2,8 @@ TEMPLATE=subdirs
 SUBDIRS = \
        ut_location/ \
        ut_route/ \
+       ut_gpscontroller/ \
+
+check.target = check
+check.CONFIG = recursive
+QMAKE_EXTRA_TARGETS += check
index 49f774b..6b92eb4 100644 (file)
@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: ut_gpscontroller
-# Generated by qmake (2.01a) (Qt 4.6.2) on: Wed Apr 14 08:39:47 2010
+# Generated by qmake (2.01a) (Qt 4.6.2) on: Mon Apr 19 11:20:53 2010
 # Project:  ut_gpscontroller.pro
 # Template: app
 # Command: /usr/bin/qmake -unix -o Makefile ut_gpscontroller.pro
@@ -184,6 +184,9 @@ distclean: clean
        -$(DEL_FILE) Makefile
 
 
+check: ut_gpscontroller
+       ./ut_gpscontroller
+
 mocclean: compiler_moc_header_clean compiler_moc_source_clean
 
 mocables: compiler_moc_header_make_all compiler_moc_source_make_all
index bc0a2a9..5ea456f 100755 (executable)
Binary files a/zouba/tests/ut_gpscontroller/ut_gpscontroller and b/zouba/tests/ut_gpscontroller/ut_gpscontroller differ
index fc31332..bbe467c 100644 (file)
@@ -88,10 +88,10 @@ void MyGpsControllerPrivate::setUseFakeLocation( bool useFake )
 
 void MyGpsControllerPrivate::updateLocation()
 {
-  if ( !m_useFakeLocation ) {
+  if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
     delete m_currentLocation;
-    m_currentLocation = new Location();
   }
+  m_currentLocation = new Location( "livegps" );
 }
 
 void Ut_GpsController::init()
@@ -152,7 +152,7 @@ void Ut_GpsController::testFakeGps()
 
   m_subject_p->updateLocation(); // pretend GPS has given an update
   Location *gpsLocation = m_subject_p->m_currentLocation; // position from GPS
-  Location *fakeLocation = new Location();
+  Location *fakeLocation = new Location("fakegps");
 
   // make test call
   m_subject->useFakeGps( fakeLocation ); // ownership -> m_subject
@@ -169,10 +169,12 @@ void Ut_GpsController::testFakeGps()
 
   // both args should be the fake gps position supplied to useFakeGps()
   arguments = spy.takeFirst();
-  QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
+  QCOMPARE( arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation );
+  QCOMPARE( arguments.at(0).value<Location*>()->label(), QString( "fakegps" ) );
   arguments = spy.takeFirst();
-  QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
-  QCOMPARE(m_subject_p->m_currentLocation, fakeLocation);
+  QCOMPARE( arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation );
+  QCOMPARE( arguments.at(0).value<Location*>()->label(), QString( "fakegps" ) );
+  QCOMPARE( m_subject_p->m_currentLocation, fakeLocation );
 
   // should not be the gpsLocation or zero
   QVERIFY(m_subject_p->m_currentLocation != gpsLocation);
@@ -185,11 +187,11 @@ void Ut_GpsController::testFakeGps()
   // gps should be on
   QCOMPARE(m_subject_p->m_gpsOn, true);
 
-  // should be zero
-  QVERIFY(m_subject_p->m_currentLocation == 0);
-
-  // should not get any signals because useFakeGps sets the location to 0
-  QVERIFY2(spy.count()==0, "should not receive any signals" );
+  QVERIFY2(spy.count()==1, "should get a locationChanged signal from getGps" );
+  arguments = spy.takeFirst();
+  QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
+  QCOMPARE( arguments.at(0).value<Location*>()->label(), QString( "livegps" ) );
+  QVERIFY(m_subject_p->m_currentLocation != fakeLocation);
 
   // fake a GPS update
   m_subject_p->updateLocation(); // pretend GPS has given an update
@@ -201,7 +203,36 @@ void Ut_GpsController::testFakeGps()
   QCOMPARE(spy.count(), 1);
   arguments = spy.takeFirst();
   QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
+  QCOMPARE( arguments.at(0).value<Location*>()->label(), QString( "livegps" ) );
   QVERIFY(m_subject_p->m_currentLocation != 0);
 }
 
+void Ut_GpsController::testLiveToFakeToLive()
+{
+  m_subject_p->updateLocation(); // pretend GPS has given an update
+  Location *fakeLocation = new Location();
+
+  m_subject->useFakeGps( fakeLocation ); // ownership -> m_subject
+  m_subject->getGps();
+
+  // switch back to live GPS
+  m_subject->useLiveGps();
+  m_subject->getGps();
+
+  // fake a GPS update
+  m_subject_p->updateLocation(); // pretend GPS has given an update
+
+  // get GPS location
+  m_subject->getGps();
+
+  m_subject->useFakeGps( fakeLocation ); // ownership -> m_subject
+  m_subject->getGps();
+
+  // fake a GPS update
+  m_subject_p->updateLocation(); // pretend GPS has given an update
+
+  // get GPS location
+  m_subject->getGps();
+}
+
 QTEST_APPLESS_MAIN(Ut_GpsController)
index 92d726e..50fdcb7 100644 (file)
@@ -26,6 +26,7 @@ private slots:
   void testGetGpsWithNoGpsUpdates();
   void testGetGpsWithGpsUpdates();
   void testFakeGps();
+  void testLiveToFakeToLive();
 
 private:
   GpsController *m_subject;
index 7a778d9..a2cf2bb 100644 (file)
@@ -36,3 +36,6 @@ HEADERS += \
   $$ZOUBASRC/location.h \
   $$ZOUBASRC/location_p.h \
 
+QMAKE_EXTRA_TARGETS += check
+check.depends = $$TARGET
+check.commands = ./$$TARGET
index 9923ffd..03e058e 100644 (file)
@@ -32,3 +32,6 @@ HEADERS += \
   $$ZOUBASRC/location.h \
   $$ZOUBASRC/location_p.h \
 
+QMAKE_EXTRA_TARGETS += check
+check.depends = $$TARGET
+check.commands = ./$$TARGET
index 5dc7779..06f65dc 100644 (file)
@@ -34,3 +34,6 @@ HEADERS += \
   $$ZOUBASRC/location.h \
   $$ZOUBASRC/location_p.h \
 
+QMAKE_EXTRA_TARGETS += check
+check.depends = $$TARGET
+check.commands = ./$$TARGET