/[pcre]/code/trunk/pcrecpp_unittest.cc
ViewVC logotype

Diff of /code/trunk/pcrecpp_unittest.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 179 by ph10, Wed Jun 13 08:53:45 2007 UTC revision 263 by ph10, Mon Nov 12 16:53:25 2007 UTC
# Line 33  Line 33 
33  //  //
34  // TODO: Test extractions for PartialMatch/Consume  // TODO: Test extractions for PartialMatch/Consume
35    
36    #ifdef HAVE_CONFIG_H
37    #include "config.h"
38    #endif
39    
40  #include <stdio.h>  #include <stdio.h>
41  #include <cassert>  #include <cassert>
42  #include <vector>  #include <vector>
 #include "config.h"  
43  #include "pcrecpp.h"  #include "pcrecpp.h"
44    
45  using pcrecpp::StringPiece;  using pcrecpp::StringPiece;
# Line 107  static void LeakTest() { Line 110  static void LeakTest() {
110        initial_size = VirtualProcessSize();        initial_size = VirtualProcessSize();
111        printf("Size after 50000: %llu\n", initial_size);        printf("Size after 50000: %llu\n", initial_size);
112      }      }
113      char buf[100];      char buf[100];  // definitely big enough
114      snprintf(buf, sizeof(buf), "pat%09d", i);      sprintf(buf, "pat%09d", i);
115      RE newre(buf);      RE newre(buf);
116    }    }
117    uint64 final_size = VirtualProcessSize();    uint64 final_size = VirtualProcessSize();
# Line 854  int main(int argc, char** argv) { Line 857  int main(int argc, char** argv) {
857    CHECK_EQ(s, string("ruby"));    CHECK_EQ(s, string("ruby"));
858    CHECK_EQ(i, 1234);    CHECK_EQ(i, 1234);
859    
860      // Ignore non-void* NULL arg
861      CHECK(RE("he(.*)lo").FullMatch("hello", (char*)NULL));
862      CHECK(RE("h(.*)o").FullMatch("hello", (string*)NULL));
863      CHECK(RE("h(.*)o").FullMatch("hello", (StringPiece*)NULL));
864      CHECK(RE("(.*)").FullMatch("1234", (int*)NULL));
865      CHECK(RE("(.*)").FullMatch("1234567890123456", (long long*)NULL));
866      CHECK(RE("(.*)").FullMatch("123.4567890123456", (double*)NULL));
867      CHECK(RE("(.*)").FullMatch("123.4567890123456", (float*)NULL));
868    
869      // Fail on non-void* NULL arg if the match doesn't parse for the given type.
870      CHECK(!RE("h(.*)lo").FullMatch("hello", &s, (char*)NULL));
871      CHECK(!RE("(.*)").FullMatch("hello", (int*)NULL));
872      CHECK(!RE("(.*)").FullMatch("1234567890123456", (int*)NULL));
873      CHECK(!RE("(.*)").FullMatch("hello", (double*)NULL));
874      CHECK(!RE("(.*)").FullMatch("hello", (float*)NULL));
875    
876    // Ignored arg    // Ignored arg
877    CHECK(RE("(\\w+)(:)(\\d+)").FullMatch("ruby:1234", &s, (void*)NULL, &i));    CHECK(RE("(\\w+)(:)(\\d+)").FullMatch("ruby:1234", &s, (void*)NULL, &i));
878    CHECK_EQ(s, string("ruby"));    CHECK_EQ(s, string("ruby"));
# Line 905  int main(int argc, char** argv) { Line 924  int main(int argc, char** argv) {
924      CHECK(!RE("(\\d+)").FullMatch("4294967296", &v));      CHECK(!RE("(\\d+)").FullMatch("4294967296", &v));
925    }    }
926  #ifdef HAVE_LONG_LONG  #ifdef HAVE_LONG_LONG
927    # if defined(__MINGW__) || defined(__MINGW32__)
928    #   define LLD "%I64d"
929    #   define LLU "%I64u"
930    # else
931    #   define LLD "%lld"
932    #   define LLU "%llu"
933    # endif
934    {    {
935      long long v;      long long v;
936      static const long long max_value = 0x7fffffffffffffffLL;      static const long long max_value = 0x7fffffffffffffffLL;
937      static const long long min_value = -max_value - 1;      static const long long min_value = -max_value - 1;
938      char buf[32];      char buf[32];  // definitely big enough for a long long
939    
940      CHECK(RE("(-?\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);      CHECK(RE("(-?\\d+)").FullMatch("100", &v)); CHECK_EQ(v, 100);
941      CHECK(RE("(-?\\d+)").FullMatch("-100",&v)); CHECK_EQ(v, -100);      CHECK(RE("(-?\\d+)").FullMatch("-100",&v)); CHECK_EQ(v, -100);
942    
943      snprintf(buf, sizeof(buf), "%lld", max_value);      sprintf(buf, LLD, max_value);
944      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);
945    
946      snprintf(buf, sizeof(buf), "%lld", min_value);      sprintf(buf, LLD, min_value);
947      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, min_value);      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, min_value);
948    
949      snprintf(buf, sizeof(buf), "%lld", max_value);      sprintf(buf, LLD, max_value);
950      assert(buf[strlen(buf)-1] != '9');      assert(buf[strlen(buf)-1] != '9');
951      buf[strlen(buf)-1]++;      buf[strlen(buf)-1]++;
952      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));
953    
954      snprintf(buf, sizeof(buf), "%lld", min_value);      sprintf(buf, LLD, min_value);
955      assert(buf[strlen(buf)-1] != '9');      assert(buf[strlen(buf)-1] != '9');
956      buf[strlen(buf)-1]++;      buf[strlen(buf)-1]++;
957      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));      CHECK(!RE("(-?\\d+)").FullMatch(buf, &v));
# Line 936  int main(int argc, char** argv) { Line 962  int main(int argc, char** argv) {
962      unsigned long long v;      unsigned long long v;
963      long long v2;      long long v2;
964      static const unsigned long long max_value = 0xffffffffffffffffULL;      static const unsigned long long max_value = 0xffffffffffffffffULL;
965      char buf[32];      char buf[32];  // definitely big enough for a unsigned long long
966    
967      CHECK(RE("(-?\\d+)").FullMatch("100",&v)); CHECK_EQ(v, 100);      CHECK(RE("(-?\\d+)").FullMatch("100",&v)); CHECK_EQ(v, 100);
968      CHECK(RE("(-?\\d+)").FullMatch("-100",&v2)); CHECK_EQ(v2, -100);      CHECK(RE("(-?\\d+)").FullMatch("-100",&v2)); CHECK_EQ(v2, -100);
969    
970      snprintf(buf, sizeof(buf), "%llu", max_value);      sprintf(buf, LLU, max_value);
971      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);      CHECK(RE("(-?\\d+)").FullMatch(buf,&v)); CHECK_EQ(v, max_value);
972    
973      assert(buf[strlen(buf)-1] != '9');      assert(buf[strlen(buf)-1] != '9');
# Line 1122  int main(int argc, char** argv) { Line 1148  int main(int argc, char** argv) {
1148      printf("Testing UTF-8 handling\n");      printf("Testing UTF-8 handling\n");
1149    
1150      // Three Japanese characters (nihongo)      // Three Japanese characters (nihongo)
1151      const char utf8_string[] = {      const unsigned char utf8_string[] = {
1152           0xe6, 0x97, 0xa5, // 65e5           0xe6, 0x97, 0xa5, // 65e5
1153           0xe6, 0x9c, 0xac, // 627c           0xe6, 0x9c, 0xac, // 627c
1154           0xe8, 0xaa, 0x9e, // 8a9e           0xe8, 0xaa, 0x9e, // 8a9e
1155           0           0
1156      };      };
1157      const char utf8_pattern[] = {      const unsigned char utf8_pattern[] = {
1158           '.',           '.',
1159           0xe6, 0x9c, 0xac, // 627c           0xe6, 0x9c, 0xac, // 627c
1160           '.',           '.',

Legend:
Removed from v.179  
changed lines
  Added in v.263

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12