1cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/*
2cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Copyright (C) 2012 The Android Open Source Project
3cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes *
4cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * you may not use this file except in compliance with the License.
6cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * You may obtain a copy of the License at
7cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes *
8cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes *
10cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * See the License for the specific language governing permissions and
14cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * limitations under the License.
15cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes */
16cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes
17cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <gtest/gtest.h>
18cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes
19cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <sys/types.h>
20cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <regex.h>
21cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes
22cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott HughesTEST(regex, smoke) {
23cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  // A quick test of all the regex functions.
24cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  regex_t re;
25cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  ASSERT_EQ(0, regcomp(&re, "ab*c", 0));
26cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  ASSERT_EQ(0, regexec(&re, "abbbc", 0, NULL, 0));
27cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  ASSERT_EQ(REG_NOMATCH, regexec(&re, "foo", 0, NULL, 0));
28cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes
29cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  char buf[80];
30cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  regerror(REG_NOMATCH, &re, buf, sizeof(buf));
31063525c61d24776094d76971f33920e2a2079530Elliott Hughes#if defined(__BIONIC__)
32cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  ASSERT_STREQ("regexec() failed to match", buf);
33cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#else
34cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  ASSERT_STREQ("No match", buf);
35cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#endif
36cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes
37cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes  regfree(&re);
38cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes}
39