/[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 256 by ph10, Wed Sep 19 08:57:53 2007 UTC revision 263 by ph10, Mon Nov 12 16:53:25 2007 UTC
# Line 37  Line 37 
37  #include "config.h"  #include "config.h"
38  #endif  #endif
39    
 #ifdef HAVE_WINDOWS_H  
 #define snprintf _snprintf  
 #endif  
   
40  #include <stdio.h>  #include <stdio.h>
41  #include <cassert>  #include <cassert>
42  #include <vector>  #include <vector>
# Line 114  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 861  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 923  int main(int argc, char** argv) { Line 935  int main(int argc, char** argv) {
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 950  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');

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

  ViewVC Help
Powered by ViewVC 1.1.5