~ubuntu-branches/debian/jessie/gsmlib/jessie

« back to all changes in this revision

Viewing changes to tests/testspb.cc

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura
  • Date: 2013-10-15 13:29:27 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131015132927-1i5iwvj21wue3uvu
Tags: 1.10+20120414.gita5e5ae9a-0.1
* Non-maintainer upload.
* Update to the latest Git version by Vianney Bouchaud.
* Use 3.0 (quilt) source package format.
* Own the run subdirectory (Closes: #689891).
* Don't remove the system user on package remove.
* Fix init script (LP: #30228).

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#endif
4
4
#include <gsmlib/gsm_sorted_phonebook.h>
5
5
#include <algorithm>
6
 
#include <strstream>
7
6
#include <iostream>
8
7
 
9
 
using namespace std;
10
 
using namespace gsmlib;
11
 
 
12
 
void printPb(PhonebookEntry &e)
 
8
void printPb(gsmlib::PhonebookEntry &e)
13
9
{
14
 
  cout << "number: " << e.telephone()
15
 
       << " text: " << e.text() << endl;
 
10
  std::cout << "number: " << e.telephone()
 
11
            << " text: " << e.text() << std::endl;
16
12
}
17
13
 
18
14
int main(int argc, char *argv[])
20
16
  try
21
17
  {
22
18
    // open phonebook file
23
 
    SortedPhonebook pb((string)"spb-copy.pb", false);
 
19
    gsmlib::SortedPhonebook pb(std::string("spb-copy.pb"), false);
24
20
    
25
21
    // print all entries
26
 
    cout << "Entries in pbs-copy.pb:" << endl;
27
 
    for (SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
28
 
      cout << "  Text: " << i->text()
29
 
           << "  Telephone: " << i->telephone() << endl;
 
22
    std::cout << "Entries in pbs-copy.pb:" << std::endl;
 
23
    for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
 
24
      std::cout << "  Text: " << i->text()
 
25
                << "  Telephone: " << i->telephone() << std::endl;
30
26
 
31
27
    // remove all entries with telephone == "0815"
32
 
    cout << "Removing entries with telephone == 0815" << endl;
33
 
    pb.setSortOrder(ByTelephone);
 
28
    std::cout << "Removing entries with telephone == 0815" << std::endl;
 
29
    pb.setSortOrder(gsmlib::ByTelephone);
34
30
 
35
 
    string s = "0815";
 
31
    std::string s = "0815";
36
32
    pb.erase(s);
37
33
 
38
 
    cout << "Entries in pbs-copy.pb<2>:" << endl;
39
 
    for (SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
40
 
      cout << "  Text: " << i->text()
41
 
           << "  Telephone: " << i->telephone() << endl;
42
 
 
 
34
    std::cout << "Entries in pbs-copy.pb<2>:" << std::endl;
 
35
    for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
 
36
      std::cout << "  Text: " << i->text()
 
37
                << "  Telephone: " << i->telephone() << std::endl;
 
38
    
43
39
    // insert some entries
44
 
    cout << "Inserting some entries" << endl;
45
 
    pb.insert(PhonebookEntryBase("08152", "new line with \r continued"));
46
 
    pb.insert(PhonebookEntryBase("41598254", "Hans-Dieter Schmidt"));
47
 
    pb.insert(PhonebookEntryBase("34058", "Hans-Dieter|Hofmann"));
 
40
    std::cout << "Inserting some entries" << std::endl;
 
41
    pb.insert(gsmlib::PhonebookEntryBase("08152", "new line with \r continued"));
 
42
    pb.insert(gsmlib::PhonebookEntryBase("41598254", "Hans-Dieter Schmidt"));
 
43
    pb.insert(gsmlib::PhonebookEntryBase("34058", "Hans-Dieter|Hofmann"));
48
44
 
49
 
    pb.setSortOrder(ByText);
50
 
    cout << "Entries in pbs-copy.pb<3>:" << endl;
51
 
    for (SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
52
 
      cout << "  Text: " << i->text()
53
 
           << "  Telephone: " << i->telephone() << endl;
 
45
    pb.setSortOrder(gsmlib::ByText);
 
46
    std::cout << "Entries in pbs-copy.pb<3>:" << std::endl;
 
47
    for (gsmlib::SortedPhonebook::iterator i = pb.begin(); i != pb.end(); ++i)
 
48
      std::cout << "  Text: " << i->text()
 
49
                << "  Telephone: " << i->telephone() << std::endl;
54
50
 
55
51
    // test erasing all "Hans-Dieter Schmidt" entries
56
 
    cout << "Erasing all Hans-Dieter Schmidt entries" << endl;
 
52
    std::cout << "Erasing all Hans-Dieter Schmidt entries" << std::endl;
57
53
    s = "Hans-Dieter Schmidt";
58
 
    pair<SortedPhonebook::iterator, SortedPhonebook::iterator> range =
 
54
    std::pair<gsmlib::SortedPhonebook::iterator, gsmlib::SortedPhonebook::iterator> range =
59
55
      pb.equal_range(s);
60
 
    cout << "About to erase:" << endl;
61
 
    for (SortedPhonebook::iterator i = range.first; i != range.second; ++i)
62
 
      cout << "  Text: " << i->text()
63
 
           << "  Telephone: " << i->telephone() << endl;
 
56
    std::cout << "About to erase:" << std::endl;
 
57
    for (gsmlib::SortedPhonebook::iterator i = range.first; i != range.second; ++i)
 
58
      std::cout << "  Text: " << i->text()
 
59
                << "  Telephone: " << i->telephone() << std::endl;
64
60
    
65
61
    pb.erase(range.first, range.second);
66
62
 
67
63
    // write back to file
68
 
    cout << "Writing back to file" << endl;
 
64
    std::cout << "Writing back to file" << std::endl;
69
65
    pb.sync();
70
66
 
71
67
    // tests the NoCopy class
72
68
    //SortedPhonebook pb2("spb.pb");
73
69
    //pb2 = pb;
74
70
  }
75
 
  catch (GsmException &ge)
 
71
  catch (gsmlib::GsmException &ge)
76
72
  {
77
 
    cerr << "GsmException '" << ge.what() << "'" << endl;
 
73
    std::cerr << "GsmException '" << ge.what() << "'" << std::endl;
78
74
    return 1;
79
75
  }
80
76
  return 0;