LCOV - app.info - js/src/jsapi-tests/testExternalStrings.cpp

LCOV - code coverage report
| Current view: | directory - js/src/jsapi-tests - testExternalStrings.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 19 | 19 | 100.0 %
| Date: | 2012-07-07 | Functions: | 9 | 7 | 77.8 %

           1                 : #include "tests.h"
           2                 : #include "jsutil.h"
           3                 :
           4                 : static const jschar arr[] = {
           5                 :     'h', 'i', ',', 'd', 'o', 'n', '\'', 't', ' ', 'd', 'e', 'l', 'e', 't', 'e', ' ', 'm', 'e', '\0'
           6                 : };
           7                 : static const size_t arrlen = sizeof(arr) / sizeof(arr[0]) - 1;
           8                 :
           9                 : static int finalized1 = 0;
          10                 : static int finalized2 = 0;
          11                 :
          12                 : static void
          13                 : finalize_str(const JSStringFinalizer *fin, jschar *chars);
          14                 :
          15                 : static const JSStringFinalizer finalizer1 = { finalize_str };
          16                 : static const JSStringFinalizer finalizer2 = { finalize_str };
          17                 :
          18                 : static void
          19            2000 : finalize_str(const JSStringFinalizer *fin, jschar *chars)
          20                 : {
          21            2000 :     if (chars && js::PodEqual(const_cast<const jschar *>(chars), arr, arrlen)) {
          22            2000 :         if (fin == &finalizer1) {
          23            1000 :             ++finalized1;
          24            1000 :         } else if (fin == &finalizer2) {
          25            1000 :             ++finalized2;
          26                 :         }
          27                 :     }
          28            2000 : }
          29                 :
          30               4 : BEGIN_TEST(testExternalStrings)
          31                 : {
          32               1 :     const unsigned N = 1000;
          33                 :
          34            1001 :     for (unsigned i = 0; i < N; ++i) {
          35            1000 :         CHECK(JS_NewExternalString(cx, arr, arrlen, &finalizer1));
          36            1000 :         CHECK(JS_NewExternalString(cx, arr, arrlen, &finalizer2));
          37                 :     }
          38                 :
          39                 :     // clear that newborn root
          40               1 :     JS_NewUCStringCopyN(cx, arr, arrlen);
          41                 :
          42               1 :     JS_GC(cx);
          43                 :
          44                 :     // a generous fudge factor to account for strings rooted by conservative gc
          45               1 :     const unsigned epsilon = 10;
          46                 :
          47               1 :     CHECK((N - finalized1) < epsilon);
          48               1 :     CHECK((N - finalized2) < epsilon);
          49                 :
          50               1 :     return true;
          51                 : }
          52               2 : END_TEST(testExternalStrings)

Generated by: LCOV version 1.7