LCOV - app.info - layout/style/test/ListCSSProperties.cpp

LCOV - code coverage report
| Current view: | directory - layout/style/test - ListCSSProperties.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 34 | 30 | 88.2 %
| Date: | 2012-04-07 | Functions: | 3 | 3 | 100.0 %

           1                 : /* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is ListCSSProperties.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is the Mozilla Foundation.
          18                 :  * Portions created by the Initial Developer are Copyright (C) 2007
          19                 :  * the Initial Developer. All Rights Reserved.
          20                 :  *
          21                 :  * Contributor(s):
          22                 :  *   L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : /* build (from code) lists of all supported CSS properties */
          39                 :
          40                 : #include <stdio.h>
          41                 : #include <string.h>
          42                 : #include <stdlib.h>
          43                 :
          44                 : struct PropertyInfo {
          45                 :     const char *propName;
          46                 :     const char *domName;
          47                 : };
          48                 :
          49                 : const PropertyInfo gLonghandProperties[] = {
          50                 :
          51                 : #define CSS_PROP_DOMPROP_PREFIXED(prop_) Moz ## prop_
          52                 : #define CSS_PROP(name_, id_, method_, flags_, parsevariant_, kwtable_,       \
          53                 :                  stylestruct_, stylestructoffset_, animtype_)                \
          54                 :     { #name_, #method_ },
          55                 :
          56                 : #include "nsCSSPropList.h"
          57                 :
          58                 : #undef CSS_PROP
          59                 : #undef CSS_PROP_DOMPROP_PREFIXED
          60                 :
          61                 : };
          62                 :
          63                 : /*
          64                 :  * These are the properties for which domName in the above list should
          65                 :  * be used.  They're in the same order as the above list, with some
          66                 :  * items skipped.
          67                 :  */
          68                 : const char* gLonghandPropertiesWithDOMProp[] = {
          69                 :
          70                 : #define CSS_PROP_LIST_EXCLUDE_INTERNAL
          71                 : #define CSS_PROP(name_, id_, method_, flags_, parsevariant_, kwtable_,       \
          72                 :                  stylestruct_, stylestructoffset_, animtype_)                \
          73                 :     #name_,
          74                 :
          75                 : #include "nsCSSPropList.h"
          76                 :
          77                 : #undef CSS_PROP
          78                 : #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
          79                 :
          80                 : };
          81                 :
          82                 : const PropertyInfo gShorthandProperties[] = {
          83                 :
          84                 : #define CSS_PROP_DOMPROP_PREFIXED(prop_) Moz ## prop_
          85                 : // Need an extra level of macro nesting to force expansion of method_
          86                 : // params before they get pasted.
          87                 : #define LISTCSSPROPERTIES_INNER_MACRO(method_) #method_,
          88                 : #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_) \
          89                 :     { #name_, LISTCSSPROPERTIES_INNER_MACRO(method_) },
          90                 :
          91                 : #include "nsCSSPropList.h"
          92                 :
          93                 : #undef CSS_PROP_SHORTHAND
          94                 : #undef LISTCSSPROPERTIES_INNER_MACRO
          95                 : #undef CSS_PROP_DOMPROP_PREFIXED
          96                 :
          97                 : };
          98                 :
          99                 : /* see gLonghandPropertiesWithDOMProp */
         100                 : const char* gShorthandPropertiesWithDOMProp[] = {
         101                 :
         102                 : #define CSS_PROP_LIST_EXCLUDE_INTERNAL
         103                 : #define CSS_PROP_SHORTHAND(name_, id_, method_, flags_) \
         104                 :     #name_,
         105                 :
         106                 : #include "nsCSSPropList.h"
         107                 :
         108                 : #undef CSS_PROP_SHORTHAND
         109                 : #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
         110                 :
         111                 : };
         112                 :
         113                 :
         114                 : #define ARRAY_LENGTH(a_) (sizeof(a_)/sizeof((a_)[0]))
         115                 :
         116                 : const char *gInaccessibleProperties[] = {
         117                 :     // Don't print the properties that aren't accepted by the parser, per
         118                 :     // CSSParserImpl::ParseProperty
         119                 :     "-x-cols",
         120                 :     "-x-lang",
         121                 :     "-x-span",
         122                 :     "-x-system-font",
         123                 :     "border-end-color-value",
         124                 :     "border-end-style-value",
         125                 :     "border-end-width-value",
         126                 :     "border-left-color-value",
         127                 :     "border-left-color-ltr-source",
         128                 :     "border-left-color-rtl-source",
         129                 :     "border-left-style-value",
         130                 :     "border-left-style-ltr-source",
         131                 :     "border-left-style-rtl-source",
         132                 :     "border-left-width-value",
         133                 :     "border-left-width-ltr-source",
         134                 :     "border-left-width-rtl-source",
         135                 :     "border-right-color-value",
         136                 :     "border-right-color-ltr-source",
         137                 :     "border-right-color-rtl-source",
         138                 :     "border-right-style-value",
         139                 :     "border-right-style-ltr-source",
         140                 :     "border-right-style-rtl-source",
         141                 :     "border-right-width-value",
         142                 :     "border-right-width-ltr-source",
         143                 :     "border-right-width-rtl-source",
         144                 :     "border-start-color-value",
         145                 :     "border-start-style-value",
         146                 :     "border-start-width-value",
         147                 :     "margin-end-value",
         148                 :     "margin-left-value",
         149                 :     "margin-right-value",
         150                 :     "margin-start-value",
         151                 :     "margin-left-ltr-source",
         152                 :     "margin-left-rtl-source",
         153                 :     "margin-right-ltr-source",
         154                 :     "margin-right-rtl-source",
         155                 :     "padding-end-value",
         156                 :     "padding-left-value",
         157                 :     "padding-right-value",
         158                 :     "padding-start-value",
         159                 :     "padding-left-ltr-source",
         160                 :     "padding-left-rtl-source",
         161                 :     "padding-right-ltr-source",
         162                 :     "padding-right-rtl-source",
         163                 :     "-moz-script-level", // parsed by UA sheets only
         164                 :     "-moz-script-size-multiplier",
         165                 :     "-moz-script-min-size"
         166                 : };
         167                 :
         168                 : inline int
         169             284 : is_inaccessible(const char* aPropName)
         170                 : {
         171           12504 :     for (unsigned j = 0; j < ARRAY_LENGTH(gInaccessibleProperties); ++j) {
         172           12267 :         if (strcmp(aPropName, gInaccessibleProperties[j]) == 0)
         173              47 :             return 1;
         174                 :     }
         175             237 :     return 0;
         176                 : }
         177                 :
         178                 : void
         179               2 : print_array(const char *aName,
         180                 :             const PropertyInfo *aProps, unsigned aPropsLength,
         181                 :             const char * const * aDOMProps, unsigned aDOMPropsLength)
         182                 : {
         183               2 :     printf("var %s = [\n", aName);
         184                 :
         185               2 :     int first = 1;
         186               2 :     unsigned j = 0; // index into DOM prop list
         187             286 :     for (unsigned i = 0; i < aPropsLength; ++i) {
         188             284 :         const PropertyInfo *p = aProps + i;
         189                 :
         190             284 :         if (is_inaccessible(p->propName))
         191                 :             // inaccessible properties never have DOM props, so don't
         192                 :             // worry about incrementing j.  The assertion below will
         193                 :             // catch if they do.
         194              47 :             continue;
         195                 :
         196             237 :         if (first)
         197               2 :             first = 0;
         198                 :         else
         199             235 :             printf(",\n");
         200                 :
         201             237 :         printf("\t{ name: \"%s\", prop: ", p->propName);
         202             237 :         if (j >= aDOMPropsLength || strcmp(p->propName, aDOMProps[j]) != 0)
         203               0 :             printf("null");
         204                 :         else {
         205             237 :             ++j;
         206             237 :             if (strncmp(p->domName, "Moz", 3) == 0)
         207              86 :                 printf("\"%s\"", p->domName);
         208                 :             else
         209                 :                 // lowercase the first letter
         210             151 :                 printf("\"%c%s\"", p->domName[0] + 32, p->domName + 1);
         211                 :         }
         212             237 :         printf("}");
         213                 :     }
         214                 :
         215               2 :     if (j != aDOMPropsLength) {
         216               0 :         fprintf(stderr, "Assertion failure %s:%d\n", __FILE__, __LINE__);
         217               0 :         fprintf(stderr, "j==%d, aDOMPropsLength == %d\n", j, aDOMPropsLength);
         218               0 :         exit(1);
         219                 :     }
         220                 :
         221               2 :     printf("\n];\n\n");
         222               2 : }
         223                 :
         224                 : int
         225               1 : main()
         226                 : {
         227                 :     print_array("gLonghandProperties",
         228                 :                 gLonghandProperties,
         229                 :                 ARRAY_LENGTH(gLonghandProperties),
         230                 :                 gLonghandPropertiesWithDOMProp,
         231               1 :                 ARRAY_LENGTH(gLonghandPropertiesWithDOMProp));
         232                 :     print_array("gShorthandProperties",
         233                 :                 gShorthandProperties,
         234                 :                 ARRAY_LENGTH(gShorthandProperties),
         235                 :                 gShorthandPropertiesWithDOMProp,
         236               1 :                 ARRAY_LENGTH(gShorthandPropertiesWithDOMProp));
         237               1 :     return 0;
         238                 : }

Generated by: LCOV version 1.7