LCOV - lcov.info - ept/apt/version.test.h

LTP GCOV extension - code coverage report
Current view: | directory - ept/apt - version.test.h
Test: | lcov.info
Date: | 2008-08-14 |  | Instrumented lines: | 71
Code covered: | 100.0 % |  | Executed lines: | 71

           1                 : /*
           2                 :  * Copyright (C) 2007  Enrico Zini <enrico@enricozini.org>
           3                 :  *
           4                 :  * This library is free software; you can redistribute it and/or
           5                 :  * modify it under the terms of the GNU Lesser General Public
           6                 :  * License as published by the Free Software Foundation; either
           7                 :  * version 2.1 of the License, or (at your option) any later version.
           8                 :  *
           9                 :  * This library is distributed in the hope that it will be useful,
          10                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
          11                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
          12                 :  * Lesser General Public License for more details.
          13                 :  *
          14                 :  * You should have received a copy of the GNU Lesser General Public
          15                 :  * License along with this library; if not, write to the Free Software
          16                 :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
          17                 :  */
          18                 :
          19                 : #include <ept/test.h>
          20                 : #include <ept/apt/version.h>
          21                 :
          22                 : using namespace std;
          23                 : using namespace ept::apt;
          24                 :
          25                 : struct TestAptVersion {
          26                 :
          27                 :     // Basic test for invalid version
          28               1 :     Test invalid()
          29                 :     {
          30               1 :         Version test;
          31                 :
          32               1 :         assert_eq(test.name(), "");
          33               1 :         assert_eq(test.version(), "");
          34               1 :         assert_eq(test.isValid(), false);
          35                 :
          36               1 :         string p = test.name();
          37                 :
          38               1 :         assert_eq(p, string());
          39               1 :     }
          40                 :
          41                 :     // Basic test for version
          42               1 :     Test basic()
          43                 :     {
          44               1 :         Version test("test", "1.0");
          45                 :
          46               2 :         assert_eq(test.name(), "test");
          47               1 :         assert_eq(test.version(), "1.0");
          48               1 :         assert_eq(test.isValid(), true);
          49                 :
          50               1 :         string p = test.name();
          51                 :
          52               1 :         assert_eq(p, "test");
          53                 :
          54               1 :         Version v(p, "1.1");
          55               2 :         assert_eq(v.name(), "test");
          56               1 :         assert_eq(v.version(), "1.1");
          57               1 :         assert_eq(v.isValid(), true);
          58               1 :     }
          59                 :
          60                 :     // Comparison semanthics
          61               1 :     Test comparison()
          62                 :     {
          63               1 :         Version test("test", "1.0");
          64               2 :         Version test1("test", "1.0");
          65                 :
          66               2 :         assert(test == test1);
          67               2 :         assert(! (test != test1));
          68               2 :         assert(! (test < test1));
          69               2 :         assert(! (test > test1));
          70               2 :         assert(test <= test1);
          71               2 :         assert(test >= test1);
          72                 :
          73                 :
          74               2 :         Version test2("test2", "1.0");
          75                 :
          76               2 :         assert(test != test2);
          77               2 :         assert(test != test2);
          78               2 :         assert(test < test2);
          79               2 :         assert(! (test > test2));
          80               2 :         assert(test <= test2);
          81               2 :         assert(! (test >= test2));
          82                 :
          83                 :
          84               2 :         Version test3("test", "2.0");
          85                 :
          86               2 :         assert(test != test3);
          87               2 :         assert(test != test3);
          88               2 :         assert(test < test3);
          89               2 :         assert(! (test > test3));
          90               2 :         assert(test <= test3);
          91               2 :         assert(! (test >= test3));
          92               1 :     }
          93                 :
          94                 :     // Value-copy semanthics
          95               1 :     Test valueCopy()
          96                 :     {
          97               1 :         Version test("test", "1.0");
          98               1 :         Version test1 = test;
          99                 :
         100               1 :         assert(test == test1);
         101                 :
         102               1 :         Version test2;
         103               1 :         test2 = test;
         104               1 :         assert(test == test2);
         105               2 :         assert(test1 == test2);
         106                 :
         107               2 :         Version test3("test", "1.0");
         108               2 :         assert(test == test3);
         109               2 :         assert(test1 == test3);
         110               2 :         assert(test2 == test3);
         111               1 :     }
         112                 :
         113                 :     // Extraction of upstream version
         114               1 :     Test upstreamVersion()
         115                 :     {
         116               1 :         assert_eq(Version("a", "10.0").upstreamVersion(), "10.0");
         117               2 :         assert_eq(Version("a", "10.0-1").upstreamVersion(), "10.0");
         118               2 :         assert_eq(Version("a", "10.0~foo.1-1.0").upstreamVersion(), "10.0~foo.1");
         119               2 :         assert_eq(Version("a", "1.0:10.0~foo.1-1.0").upstreamVersion(), "10.0~foo.1");
         120               1 :     }
         121                 :
         122                 :     // Debian policy comparison semanthics
         123               1 :     Test policyComparison()
         124                 :     {
         125               1 :         assert(Version("a", "10.0") > Version("a", "2.1"));
         126               2 :         assert(Version("a", "1:10.0") < Version("a", "2:2.1"));
         127               2 :         assert(Version("a", "10.0-1") < Version("a", "10.0-2"));
         128               2 :         assert(Version("a", "10.0-2") > Version("a", "10.0-1"));
         129               2 :         assert(Version("a", "1:10.0-1") <= Version("a", "1:10.0-1"));
         130               2 :         assert(Version("a", "1:10.0-1") >= Version("a", "1:10.0-1"));
         131                 :         // TODO: add more
         132               1 :     }
         133                 :
         134                 : };
         135                 :
         136                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6