OSDN Git Service

ae990ca166f83cdcd4637df640fca78e4d5efa2c
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / ext / rope / 3.cc
1 // Copyright (C) 2004, 2005 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // 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
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING.  If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18
19 // rope (SGI extension)
20
21 #include <ext/rope>
22 #include <testsuite_hooks.h>
23
24 const char base[] =
25 "Happy families are all alike; every unhappy family is unhappy in   \
26 its own way.                                                        \
27                                                                     \
28 Everything was in confusion in the Oblonskys' house.  The wife      \
29 had discovered that the husband was carrying on an intrigue with    \
30 a French girl, who had been a governess in their family, and she    \
31 had announced to her husband that she could not go on living in     \
32 the same house with him.  This position of affairs had now lasted   \
33 three days, and not only the husband and wife themselves, but all   \
34 the members of their family and household, were painfully           \
35 conscious of it.  Every person in the house felt that there was     \
36 so sense in their living together, and that the stray people        \
37 brought together by chance in any inn had more in common with one   \
38 another than they, the members of the family and household of the   \
39 Oblonskys.  The wife did not leave her own room, the husband had    \
40 not been at home for three days.  The children ran wild all over    \
41 the house; the English governess quarreled with the housekeeper,    \
42 and wrote to a friend asking her to look out for a new situation    \
43 for her; the man-cook had walked off the day before just at         \
44 dinner time; the kitchen-maid, and the coachman had given           \
45 warning."                                                       
46   ;
47
48 int baselen = sizeof(base) - 1;
49
50 template<class StringType>
51 StringType
52 multiply(const StringType& s, int n)
53 {
54   StringType result;
55   while (n > 0)
56     {
57       result += s;
58       --n;
59     }
60   return result;
61 }
62
63 template <class StringType>
64 StringType
65 mung_substrings(const StringType& s, int len, int n, int skip)
66 {
67   StringType result;
68   int start = 0;
69   while (n > 0)
70     {
71       StringType tmp = s.substr (start, len);
72       result += tmp;
73       --n;
74       start += skip;
75     }
76   return result;
77 }
78
79 void 
80 test01()
81 {
82   using namespace __gnu_cxx;
83   bool test __attribute__((unused)) = true;
84
85   crope r;
86   r = multiply(crope(base), 100000);
87
88   crope r1;
89   r1 = mung_substrings(r, 100000, 500, 73);
90
91   VERIFY( r1.size() == 50000000 );
92   VERIFY( r1.substr(88888, 6)[0] == 's' );
93   VERIFY( r1.substr(88888, 6)[2] == 'h' );
94 }
95
96 int main()
97 {
98   test01();
99   return 0;
100 }