├── .github
└── workflows
│ ├── main.yml
│ └── pull_requests.yml
├── .gitignore
├── .idea
├── .name
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── layoutSnapshots
│ ├── e1_flat_layout.json
│ ├── e1_flat_layout_240x320.json
│ ├── e2_nested_layout.json
│ └── e2_nested_layout_only_specified views.json
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── e1_flat_layout.xml
│ │ └── e2_nested_layout.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── redapparat
│ └── demo
│ └── DemoLayoutTest.kt
├── build.gradle
├── deploy.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── layoutverifier-tests
├── .gitignore
├── build.gradle
├── layoutSnapshots
│ ├── flat_layout.json
│ ├── flat_layout__small_screen.json
│ ├── flat_layout__view_subset.json
│ ├── generated_view_id.json
│ ├── nested_layout.json
│ ├── recycler_view__3_elements.json
│ ├── recycler_view__50_elements.json
│ └── schema_v3_features.json
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ └── res
│ │ └── layout
│ │ ├── case_001.xml
│ │ ├── case_002.xml
│ │ ├── case_003.xml
│ │ ├── case_004.xml
│ │ ├── case_005.xml
│ │ ├── case_006.xml
│ │ ├── case_007.xml
│ │ ├── case_008.xml
│ │ ├── case_009.xml
│ │ ├── case_014.xml
│ │ └── case_015.xml
│ └── test
│ └── java
│ └── com
│ └── redapparat
│ └── layoutverifier
│ └── tests
│ ├── LayoutVerifierIntegrationTests.kt
│ └── view
│ └── SimpleAdapter.kt
├── layoutverifier
├── .gitignore
├── build.gradle
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ └── java
│ │ └── com
│ │ └── redapparat
│ │ └── layoutverifier
│ │ ├── LayoutMatcher.kt
│ │ ├── LayoutVerifier.kt
│ │ ├── Schemas.kt
│ │ ├── extractor
│ │ ├── CommonExtractor.kt
│ │ ├── CompositeFeatureExtractor.kt
│ │ ├── DefaultFeatures.kt
│ │ ├── FeatureExtractor.kt
│ │ └── content
│ │ │ └── TextViewExtractor.kt
│ │ └── serializer
│ │ ├── GsonSerializer.kt
│ │ └── Serializer.kt
│ └── test
│ └── java
│ └── com
│ └── redapparat
│ └── layoutverifier
│ ├── ExampleUnitTest.kt
│ └── SchemasTest.kt
└── settings.gradle
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Android Master CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - 'master'
7 |
8 | jobs:
9 | test:
10 | name: Run Unit Tests
11 | runs-on: ubuntu-18.04
12 |
13 | steps:
14 | - uses: actions/checkout@v1
15 | - name: set up JDK 1.9
16 | uses: actions/setup-java@v1
17 | with:
18 | java-version: 1.9
19 | - name: Unit tests
20 | run: bash ./gradlew :layoutverifier-tests:testDebugUnitTest --stacktrace
21 |
--------------------------------------------------------------------------------
/.github/workflows/pull_requests.yml:
--------------------------------------------------------------------------------
1 | name: Android Pull Request
2 |
3 | on: pull_request
4 |
5 | jobs:
6 | test:
7 | name: Run Unit Tests
8 | runs-on: ubuntu-18.04
9 |
10 | steps:
11 | - uses: actions/checkout@v1
12 | - name: set up JDK 1.9
13 | uses: actions/setup-java@v1
14 | with:
15 | java-version: 1.9
16 | - name: Unit tests
17 | run: bash ./gradlew :layoutverifier-tests:testDebugUnitTest --stacktrace
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | My Application
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LayoutVerifier
2 |
3 | 
4 |
5 | Test Android layouts without device. LayoutVerifier is a Robolectric-based testing library which
6 | makes sure your Android screens are never broken again.
7 |
8 | **What's in the box:**
9 | - Library which makes sure that your Views are where they are supposed to be on the screen.
10 | - No need for an emulator.
11 | - No need for a build plugin or complex initial setup. Single library is all it takes.
12 | - As little as 3 lines to write a test.
13 | - Similar to Screenshot tests but much faster.
14 |
15 | ## Usage
16 |
17 | Get started by adding LayoutVerifier to your test dependencies and do some minimal configuration:
18 |
19 | ```
20 | android {
21 |
22 | testOptions {
23 | unitTests {
24 | includeAndroidResources = true
25 | }
26 | }
27 |
28 | }
29 |
30 | dependencies {
31 |
32 | // Make sure Robolectric is included
33 |
34 | testImplementation 'com.redapparat:layoutverifier:1.1.2'
35 | }
36 |
37 | ```
38 |
39 | Then, simply write a JUnit test:
40 |
41 | ```
42 | // LayoutVerifier instance can be reused between tests
43 | val layoutVerifier = LayoutVerifier.Builder(getApplicationContext())
44 | .build()
45 |
46 | // For each new test, pick a layout and call match()
47 | layoutVerifier
48 | .layout(R.layout.myLayout)
49 | .screenSize(600, 800) // optional: screen size in DP
50 | .views( // optional: those views which you care about, otherwise compare all views
51 | R.id.buyButton,
52 | R.id.totalPrice
53 | )
54 | .match("test_case_name") // optional: arbitraty test case name which is unique to your module
55 | ```
56 |
57 | That is it. On the first run the test will pass and save a pre-recorded version of the layout to
58 | disk. Make sure to keep this file and include it into your commits.
59 |
60 | ### Updating to a new version
61 |
62 | New versions of LayoutVerifier might include new attributes into view comparison which were not previously recorded in a snapshot file. LayoutVerifier takes care of backward compatibility and generates a new snapshot file if version update is detected.
63 |
64 | As such, after upgrading to a new version you might see that snapshot files have changed. That is expected, be sure to commit them as part of your repository as you would do for any new test.
65 |
66 | ## How it works
67 |
68 | ### Concept
69 |
70 | LayoutVerifier captures essential information about your View (i.e. elements position,
71 | text content) and then compares it to a pre-recorded "standard" version of the layout. If there is
72 | no pre-recorded version available, current state of the view is assumed to be correct and then
73 | recorded as a new standard for future comparisons.
74 |
75 | If you have worked with Screenshot-tests before all of that might sound familiar to you.
76 | LayoutVerifier uses a very similar concept but instead of comparing screenshots it compares data.
77 |
78 | ### How views are compared
79 |
80 | The following view features (aka attrbiutes) are compared:
81 |
82 | - Position (left, top, right, bottom)
83 | - Text (children of a `TextView`, including `EditText` and `Button`)
84 | - Enabled state
85 | - Clickable state
86 |
87 | Furthermore, new features can easily be added by providing a custom implementation of
88 | `FeatureExtractor`.
89 |
90 | ## License
91 |
92 | ```
93 | Copyright 2020 LayoutVerifier
94 |
95 | Licensed under the Apache License, Version 2.0 (the "License");
96 | you may not use this file except in compliance with the License.
97 | You may obtain a copy of the License at
98 |
99 | http://www.apache.org/licenses/LICENSE-2.0
100 |
101 | Unless required by applicable law or agreed to in writing, software
102 | distributed under the License is distributed on an "AS IS" BASIS,
103 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104 | See the License for the specific language governing permissions and
105 | limitations under the License.
106 | ```
107 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | applicationId "com.redapparat.demo"
11 | minSdkVersion 16
12 | targetSdkVersion 29
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | testOptions {
20 | unitTests {
21 | includeAndroidResources = true
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30 | implementation 'androidx.appcompat:appcompat:1.1.0'
31 | implementation 'androidx.core:core-ktx:1.2.0'
32 |
33 | testImplementation 'junit:junit:4.12'
34 | testImplementation 'androidx.test:core:1.2.0'
35 | testImplementation 'androidx.test.ext:junit:1.1.1'
36 | testImplementation 'androidx.test:runner:1.2.0'
37 | testImplementation 'androidx.test:rules:1.2.0'
38 | testImplementation 'org.robolectric:robolectric:4.3.1'
39 | testImplementation project(':layoutverifier')
40 | }
41 |
--------------------------------------------------------------------------------
/app/layoutSnapshots/e1_flat_layout.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 600.0,
7 | "bottom": 800.0,
8 | "type": "android.widget.LinearLayout",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 600.0,
19 | "bottom": 41.0,
20 | "type": "android.widget.TextView",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "com.redapparat.demo:id/textView",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "paddingStart": 0.0,
27 | "paddingTop": 0.0,
28 | "paddingEnd": 0.0,
29 | "paddingBottom": 0.0,
30 | "text": "Hello World",
31 | "textColor": "#8a000000",
32 | "textSize": 14.0
33 | },
34 | {
35 | "left": 0.0,
36 | "top": 41.0,
37 | "right": 600.0,
38 | "bottom": 102.0,
39 | "type": "android.widget.Button",
40 | "enabled": true,
41 | "clickable": true,
42 | "id": "com.redapparat.demo:id/button",
43 | "visibility": "VISIBLE",
44 | "background": "Drawable",
45 | "paddingStart": 12.0,
46 | "paddingTop": 10.0,
47 | "paddingEnd": 12.0,
48 | "paddingBottom": 10.0,
49 | "text": "Button",
50 | "textColor": "#de000000",
51 | "textSize": 14.0
52 | }
53 | ]
54 | }
55 | }
--------------------------------------------------------------------------------
/app/layoutSnapshots/e1_flat_layout_240x320.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 240.0,
7 | "bottom": 320.0,
8 | "type": "android.widget.LinearLayout",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 240.0,
19 | "bottom": 41.0,
20 | "type": "android.widget.TextView",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "com.redapparat.demo:id/textView",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "paddingStart": 0.0,
27 | "paddingTop": 0.0,
28 | "paddingEnd": 0.0,
29 | "paddingBottom": 0.0,
30 | "text": "Hello World",
31 | "textColor": "#8a000000",
32 | "textSize": 14.0
33 | },
34 | {
35 | "left": 0.0,
36 | "top": 41.0,
37 | "right": 240.0,
38 | "bottom": 102.0,
39 | "type": "android.widget.Button",
40 | "enabled": true,
41 | "clickable": true,
42 | "id": "com.redapparat.demo:id/button",
43 | "visibility": "VISIBLE",
44 | "background": "Drawable",
45 | "paddingStart": 12.0,
46 | "paddingTop": 10.0,
47 | "paddingEnd": 12.0,
48 | "paddingBottom": 10.0,
49 | "text": "Button",
50 | "textColor": "#de000000",
51 | "textSize": 14.0
52 | }
53 | ]
54 | }
55 | }
--------------------------------------------------------------------------------
/app/layoutSnapshots/e2_nested_layout.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 600.0,
7 | "bottom": 800.0,
8 | "type": "android.widget.RelativeLayout",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 600.0,
19 | "bottom": 41.0,
20 | "type": "android.widget.LinearLayout",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "No id",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "children": [
27 | {
28 | "left": 298.0,
29 | "top": 0.0,
30 | "right": 301.0,
31 | "bottom": 41.0,
32 | "type": "android.widget.TextView",
33 | "enabled": true,
34 | "clickable": false,
35 | "id": "com.redapparat.demo:id/text_top",
36 | "visibility": "VISIBLE",
37 | "background": "null",
38 | "paddingStart": 0.0,
39 | "paddingTop": 0.0,
40 | "paddingEnd": 0.0,
41 | "paddingBottom": 0.0,
42 | "text": "Top",
43 | "textColor": "#8a000000",
44 | "textSize": 14.0
45 | }
46 | ]
47 | },
48 | {
49 | "left": 0.0,
50 | "top": 759.0,
51 | "right": 600.0,
52 | "bottom": 800.0,
53 | "type": "android.widget.LinearLayout",
54 | "enabled": true,
55 | "clickable": false,
56 | "id": "No id",
57 | "visibility": "VISIBLE",
58 | "background": "null",
59 | "children": [
60 | {
61 | "left": 297.0,
62 | "top": 0.0,
63 | "right": 303.0,
64 | "bottom": 41.0,
65 | "type": "android.widget.TextView",
66 | "enabled": true,
67 | "clickable": false,
68 | "id": "com.redapparat.demo:id/text_bottom",
69 | "visibility": "VISIBLE",
70 | "background": "null",
71 | "paddingStart": 0.0,
72 | "paddingTop": 0.0,
73 | "paddingEnd": 0.0,
74 | "paddingBottom": 0.0,
75 | "text": "Bottom",
76 | "textColor": "#8a000000",
77 | "textSize": 14.0
78 | }
79 | ]
80 | }
81 | ]
82 | }
83 | }
--------------------------------------------------------------------------------
/app/layoutSnapshots/e2_nested_layout_only_specified views.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "children": [
5 | {
6 | "children": [
7 | {
8 | "left": 298.0,
9 | "top": 0.0,
10 | "right": 301.0,
11 | "bottom": 41.0,
12 | "type": "android.widget.TextView",
13 | "enabled": true,
14 | "clickable": false,
15 | "id": "com.redapparat.demo:id/text_top",
16 | "visibility": "VISIBLE",
17 | "background": "null",
18 | "paddingStart": 0.0,
19 | "paddingTop": 0.0,
20 | "paddingEnd": 0.0,
21 | "paddingBottom": 0.0,
22 | "text": "Top",
23 | "textColor": "#8a000000",
24 | "textSize": 14.0
25 | }
26 | ]
27 | },
28 | {
29 | "children": [
30 | {
31 | "left": 297.0,
32 | "top": 0.0,
33 | "right": 303.0,
34 | "bottom": 41.0,
35 | "type": "android.widget.TextView",
36 | "enabled": true,
37 | "clickable": false,
38 | "id": "com.redapparat.demo:id/text_bottom",
39 | "visibility": "VISIBLE",
40 | "background": "null",
41 | "paddingStart": 0.0,
42 | "paddingTop": 0.0,
43 | "paddingEnd": 0.0,
44 | "paddingBottom": 0.0,
45 | "text": "Bottom",
46 | "textColor": "#8a000000",
47 | "textSize": 14.0
48 | }
49 | ]
50 | }
51 | ]
52 | }
53 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/e1_flat_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/e2_nested_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
21 |
22 |
27 |
28 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/redapparat/demo/DemoLayoutTest.kt:
--------------------------------------------------------------------------------
1 | package com.redapparat.demo
2 |
3 | import androidx.test.core.app.ApplicationProvider.getApplicationContext
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 | import com.redapparat.layoutverifier.LayoutVerifier
6 | import org.junit.Before
7 | import org.junit.Test
8 | import org.junit.runner.RunWith
9 |
10 | @RunWith(AndroidJUnit4::class)
11 | class DemoLayoutTest {
12 |
13 | lateinit var layoutVerifier: LayoutVerifier
14 |
15 | @Before
16 | fun setUp() {
17 | layoutVerifier = LayoutVerifier.Builder(getApplicationContext())
18 | .build()
19 | }
20 |
21 | @Test
22 | fun `Flat layout`() {
23 | layoutVerifier.layout(R.layout.e1_flat_layout)
24 | .match("e1_flat_layout")
25 | }
26 |
27 | @Test
28 | fun `Flat layout - on a small screen`() {
29 | layoutVerifier.layout(R.layout.e1_flat_layout)
30 | .screenSize(240, 320)
31 | .match("e1_flat_layout_240x320")
32 | }
33 |
34 | @Test
35 | fun `Nested layout`() {
36 | layoutVerifier.layout(R.layout.e2_nested_layout)
37 | .match("e2_nested_layout")
38 | }
39 |
40 | @Test
41 | fun `Nested layout - only check specified views`() {
42 | layoutVerifier.layout(R.layout.e2_nested_layout)
43 | .views(
44 | R.id.text_top,
45 | R.id.text_bottom
46 | )
47 | .match("e2_nested_layout_only_specified views")
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | subprojects {
4 | ext {
5 | artifactVersion = '1.1.2'
6 | }
7 | }
8 |
9 | buildscript {
10 | ext.kotlin_version = '1.3.72'
11 | repositories {
12 | google()
13 | jcenter()
14 |
15 | }
16 | dependencies {
17 | classpath 'com.android.tools.build:gradle:3.6.3'
18 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19 |
20 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
21 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
22 | }
23 | }
24 |
25 | allprojects {
26 | repositories {
27 | google()
28 | jcenter()
29 |
30 | }
31 | }
32 |
33 | task clean(type: Delete) {
34 | delete rootProject.buildDir
35 | }
36 |
--------------------------------------------------------------------------------
/deploy.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | ext {
5 | bintrayOrganisation = 'fotoapparat'
6 | bintrayRepo = 'redapparat'
7 |
8 | publishedGroupId = 'com.redapparat'
9 |
10 | siteUrl = 'https://github.com/dmitry-zaitsev/LayoutVerifier'
11 | gitUrl = 'https://github.com/dmitry-zaitsev/LayoutVerifier.git'
12 |
13 | developerId = 'fotoapparat'
14 | developerName = 'Fotoapparat'
15 | developerEmail = 'dmitry.zaicew@gmail.com'
16 |
17 | licenseName = 'The Apache Software License, Version 2.0'
18 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
19 | allLicenses = ["Apache-2.0"]
20 | }
21 |
22 | group = publishedGroupId
23 | version = libraryVersion
24 |
25 | install {
26 | repositories.mavenInstaller {
27 | pom.project {
28 | packaging 'aar'
29 | groupId publishedGroupId
30 | artifactId artifact
31 |
32 | name libraryName
33 | description libraryDescription
34 | url siteUrl
35 |
36 | licenses {
37 | license {
38 | name licenseName
39 | url licenseUrl
40 | }
41 | }
42 | developers {
43 | developer {
44 | id developerId
45 | name developerName
46 | email developerEmail
47 | }
48 | }
49 | scm {
50 | connection gitUrl
51 | developerConnection gitUrl
52 | url siteUrl
53 | }
54 | }
55 | }
56 | }
57 |
58 | task sourcesJar(type: Jar) {
59 | archiveClassifier = 'sources'
60 | from android.sourceSets.main.java.srcDirs
61 | }
62 |
63 | task javadoc(type: Javadoc) {
64 | source = android.sourceSets.main.java.srcDirs
65 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
66 | failOnError = false
67 | }
68 |
69 | task javadocJar(type: Jar, dependsOn: javadoc) {
70 | archiveClassifier = 'javadoc'
71 | from javadoc.destinationDir
72 | }
73 |
74 | artifacts {
75 | archives javadocJar
76 | archives sourcesJar
77 | }
78 |
79 | bintray {
80 | user = project.properties["bintray.user"] ?: System.getenv('BINTRAY_USER')
81 | key = project.properties["bintray.apikey"] ?: System.getenv('BINTRAY_API_KEY')
82 |
83 | configurations = ['archives']
84 | pkg {
85 | userOrg = bintrayOrganisation
86 | repo = bintrayRepo
87 | name = bintrayName
88 | desc = libraryDescription
89 | websiteUrl = siteUrl
90 | vcsUrl = gitUrl
91 | licenses = allLicenses
92 | dryRun = false
93 | publish = true
94 | override = false
95 | publicDownloadNumbers = true
96 | version {
97 | desc = libraryDescription
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitry-zaitsev/LayoutVerifier/c4af7bf2fff5d9fcf78bf37b5121bf2f70f61b21/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri May 01 23:01:39 CEST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/layoutverifier-tests/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/layoutverifier-tests/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 29
7 | buildToolsVersion "29.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 17
11 | targetSdkVersion 29
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 |
16 | testOptions {
17 | unitTests {
18 | includeAndroidResources = true
19 | }
20 | }
21 |
22 | }
23 |
24 | dependencies {
25 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
26 | implementation 'androidx.appcompat:appcompat:1.1.0'
27 | implementation 'androidx.core:core-ktx:1.2.0'
28 | implementation "androidx.recyclerview:recyclerview:1.1.0"
29 |
30 | testImplementation project(':layoutverifier')
31 | testImplementation 'junit:junit:4.12'
32 | testImplementation 'androidx.test:core:1.2.0'
33 | testImplementation 'androidx.test.ext:junit:1.1.1'
34 | testImplementation 'androidx.test:runner:1.2.0'
35 | testImplementation 'androidx.test:rules:1.2.0'
36 | testImplementation 'org.robolectric:robolectric:4.3.1'
37 | }
38 |
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/flat_layout.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 600.0,
7 | "bottom": 800.0,
8 | "type": "android.widget.RelativeLayout",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 10.0,
19 | "bottom": 41.0,
20 | "type": "android.widget.TextView",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_a",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "paddingStart": 0.0,
27 | "paddingTop": 0.0,
28 | "paddingEnd": 0.0,
29 | "paddingBottom": 0.0,
30 | "text": "TextView A",
31 | "textColor": "#8a000000",
32 | "textSize": 14.0
33 | },
34 | {
35 | "left": 0.0,
36 | "top": 41.0,
37 | "right": 10.0,
38 | "bottom": 82.0,
39 | "type": "android.widget.TextView",
40 | "enabled": true,
41 | "clickable": false,
42 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_b",
43 | "visibility": "VISIBLE",
44 | "background": "null",
45 | "paddingStart": 0.0,
46 | "paddingTop": 0.0,
47 | "paddingEnd": 0.0,
48 | "paddingBottom": 0.0,
49 | "text": "TextView B",
50 | "textColor": "#8a000000",
51 | "textSize": 14.0
52 | }
53 | ]
54 | }
55 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/flat_layout__small_screen.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 100.0,
7 | "bottom": 100.0,
8 | "type": "android.widget.LinearLayout",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 10.0,
19 | "bottom": 41.0,
20 | "type": "android.widget.TextView",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_a",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "paddingStart": 0.0,
27 | "paddingTop": 0.0,
28 | "paddingEnd": 0.0,
29 | "paddingBottom": 0.0,
30 | "text": "TextView A",
31 | "textColor": "#8a000000",
32 | "textSize": 14.0
33 | },
34 | {
35 | "left": 0.0,
36 | "top": 41.0,
37 | "right": 10.0,
38 | "bottom": 82.0,
39 | "type": "android.widget.TextView",
40 | "enabled": true,
41 | "clickable": false,
42 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_b",
43 | "visibility": "VISIBLE",
44 | "background": "null",
45 | "paddingStart": 0.0,
46 | "paddingTop": 0.0,
47 | "paddingEnd": 0.0,
48 | "paddingBottom": 0.0,
49 | "text": "TextView B",
50 | "textColor": "#8a000000",
51 | "textSize": 14.0
52 | }
53 | ]
54 | }
55 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/flat_layout__view_subset.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "children": [
5 | {
6 | "left": 0.0,
7 | "top": 41.0,
8 | "right": 10.0,
9 | "bottom": 82.0,
10 | "type": "android.widget.TextView",
11 | "enabled": true,
12 | "clickable": false,
13 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_b",
14 | "visibility": "VISIBLE",
15 | "background": "null",
16 | "paddingStart": 0.0,
17 | "paddingTop": 0.0,
18 | "paddingEnd": 0.0,
19 | "paddingBottom": 0.0,
20 | "text": "TextView B",
21 | "textColor": "#8a000000",
22 | "textSize": 14.0
23 | }
24 | ]
25 | }
26 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/generated_view_id.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 600.0,
7 | "bottom": 800.0,
8 | "type": "android.view.View",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "1 (Generated)",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "paddingStart": 0.0,
15 | "paddingTop": 0.0,
16 | "paddingEnd": 0.0,
17 | "paddingBottom": 0.0
18 | }
19 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/nested_layout.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 600.0,
7 | "bottom": 800.0,
8 | "type": "android.widget.LinearLayout",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 10.0,
19 | "bottom": 82.0,
20 | "type": "android.widget.LinearLayout",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "No id",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "children": [
27 | {
28 | "left": 0.0,
29 | "top": 0.0,
30 | "right": 10.0,
31 | "bottom": 41.0,
32 | "type": "android.widget.TextView",
33 | "enabled": true,
34 | "clickable": false,
35 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_a",
36 | "visibility": "VISIBLE",
37 | "background": "null",
38 | "paddingStart": 0.0,
39 | "paddingTop": 0.0,
40 | "paddingEnd": 0.0,
41 | "paddingBottom": 0.0,
42 | "text": "TextView A",
43 | "textColor": "#8a000000",
44 | "textSize": 14.0
45 | },
46 | {
47 | "left": 0.0,
48 | "top": 41.0,
49 | "right": 10.0,
50 | "bottom": 82.0,
51 | "type": "android.widget.TextView",
52 | "enabled": true,
53 | "clickable": false,
54 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_b",
55 | "visibility": "VISIBLE",
56 | "background": "null",
57 | "paddingStart": 0.0,
58 | "paddingTop": 0.0,
59 | "paddingEnd": 0.0,
60 | "paddingBottom": 0.0,
61 | "text": "TextView B",
62 | "textColor": "#8a000000",
63 | "textSize": 14.0
64 | }
65 | ]
66 | },
67 | {
68 | "left": 0.0,
69 | "top": 82.0,
70 | "right": 20.0,
71 | "bottom": 123.0,
72 | "type": "android.widget.LinearLayout",
73 | "enabled": true,
74 | "clickable": false,
75 | "id": "No id",
76 | "visibility": "VISIBLE",
77 | "background": "null",
78 | "children": [
79 | {
80 | "left": 0.0,
81 | "top": 0.0,
82 | "right": 10.0,
83 | "bottom": 41.0,
84 | "type": "android.widget.TextView",
85 | "enabled": true,
86 | "clickable": false,
87 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_c",
88 | "visibility": "VISIBLE",
89 | "background": "null",
90 | "paddingStart": 0.0,
91 | "paddingTop": 0.0,
92 | "paddingEnd": 0.0,
93 | "paddingBottom": 0.0,
94 | "text": "TextView C",
95 | "textColor": "#8a000000",
96 | "textSize": 14.0
97 | },
98 | {
99 | "left": 10.0,
100 | "top": 0.0,
101 | "right": 20.0,
102 | "bottom": 41.0,
103 | "type": "android.widget.TextView",
104 | "enabled": true,
105 | "clickable": false,
106 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_d",
107 | "visibility": "VISIBLE",
108 | "background": "null",
109 | "paddingStart": 0.0,
110 | "paddingTop": 0.0,
111 | "paddingEnd": 0.0,
112 | "paddingBottom": 0.0,
113 | "text": "TextView D",
114 | "textColor": "#8a000000",
115 | "textSize": 14.0
116 | }
117 | ]
118 | }
119 | ]
120 | }
121 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/recycler_view__3_elements.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 600.0,
7 | "bottom": 800.0,
8 | "type": "androidx.recyclerview.widget.RecyclerView",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 6.0,
19 | "bottom": 41.0,
20 | "type": "android.widget.TextView",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "No id",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "paddingStart": 0.0,
27 | "paddingTop": 0.0,
28 | "paddingEnd": 0.0,
29 | "paddingBottom": 0.0,
30 | "text": "Item 0",
31 | "textColor": "#8a000000",
32 | "textSize": 14.0
33 | },
34 | {
35 | "left": 0.0,
36 | "top": 41.0,
37 | "right": 6.0,
38 | "bottom": 82.0,
39 | "type": "android.widget.TextView",
40 | "enabled": true,
41 | "clickable": false,
42 | "id": "No id",
43 | "visibility": "VISIBLE",
44 | "background": "null",
45 | "paddingStart": 0.0,
46 | "paddingTop": 0.0,
47 | "paddingEnd": 0.0,
48 | "paddingBottom": 0.0,
49 | "text": "Item 1",
50 | "textColor": "#8a000000",
51 | "textSize": 14.0
52 | },
53 | {
54 | "left": 0.0,
55 | "top": 82.0,
56 | "right": 6.0,
57 | "bottom": 123.0,
58 | "type": "android.widget.TextView",
59 | "enabled": true,
60 | "clickable": false,
61 | "id": "No id",
62 | "visibility": "VISIBLE",
63 | "background": "null",
64 | "paddingStart": 0.0,
65 | "paddingTop": 0.0,
66 | "paddingEnd": 0.0,
67 | "paddingBottom": 0.0,
68 | "text": "Item 2",
69 | "textColor": "#8a000000",
70 | "textSize": 14.0
71 | }
72 | ]
73 | }
74 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/recycler_view__50_elements.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 240.0,
7 | "bottom": 320.0,
8 | "type": "androidx.recyclerview.widget.RecyclerView",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 6.0,
19 | "bottom": 41.0,
20 | "type": "android.widget.TextView",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "No id",
24 | "visibility": "VISIBLE",
25 | "background": "null",
26 | "paddingStart": 0.0,
27 | "paddingTop": 0.0,
28 | "paddingEnd": 0.0,
29 | "paddingBottom": 0.0,
30 | "text": "Item 0",
31 | "textColor": "#8a000000",
32 | "textSize": 14.0
33 | },
34 | {
35 | "left": 0.0,
36 | "top": 41.0,
37 | "right": 6.0,
38 | "bottom": 82.0,
39 | "type": "android.widget.TextView",
40 | "enabled": true,
41 | "clickable": false,
42 | "id": "No id",
43 | "visibility": "VISIBLE",
44 | "background": "null",
45 | "paddingStart": 0.0,
46 | "paddingTop": 0.0,
47 | "paddingEnd": 0.0,
48 | "paddingBottom": 0.0,
49 | "text": "Item 1",
50 | "textColor": "#8a000000",
51 | "textSize": 14.0
52 | },
53 | {
54 | "left": 0.0,
55 | "top": 82.0,
56 | "right": 6.0,
57 | "bottom": 123.0,
58 | "type": "android.widget.TextView",
59 | "enabled": true,
60 | "clickable": false,
61 | "id": "No id",
62 | "visibility": "VISIBLE",
63 | "background": "null",
64 | "paddingStart": 0.0,
65 | "paddingTop": 0.0,
66 | "paddingEnd": 0.0,
67 | "paddingBottom": 0.0,
68 | "text": "Item 2",
69 | "textColor": "#8a000000",
70 | "textSize": 14.0
71 | },
72 | {
73 | "left": 0.0,
74 | "top": 123.0,
75 | "right": 6.0,
76 | "bottom": 164.0,
77 | "type": "android.widget.TextView",
78 | "enabled": true,
79 | "clickable": false,
80 | "id": "No id",
81 | "visibility": "VISIBLE",
82 | "background": "null",
83 | "paddingStart": 0.0,
84 | "paddingTop": 0.0,
85 | "paddingEnd": 0.0,
86 | "paddingBottom": 0.0,
87 | "text": "Item 3",
88 | "textColor": "#8a000000",
89 | "textSize": 14.0
90 | },
91 | {
92 | "left": 0.0,
93 | "top": 164.0,
94 | "right": 6.0,
95 | "bottom": 205.0,
96 | "type": "android.widget.TextView",
97 | "enabled": true,
98 | "clickable": false,
99 | "id": "No id",
100 | "visibility": "VISIBLE",
101 | "background": "null",
102 | "paddingStart": 0.0,
103 | "paddingTop": 0.0,
104 | "paddingEnd": 0.0,
105 | "paddingBottom": 0.0,
106 | "text": "Item 4",
107 | "textColor": "#8a000000",
108 | "textSize": 14.0
109 | },
110 | {
111 | "left": 0.0,
112 | "top": 205.0,
113 | "right": 6.0,
114 | "bottom": 246.0,
115 | "type": "android.widget.TextView",
116 | "enabled": true,
117 | "clickable": false,
118 | "id": "No id",
119 | "visibility": "VISIBLE",
120 | "background": "null",
121 | "paddingStart": 0.0,
122 | "paddingTop": 0.0,
123 | "paddingEnd": 0.0,
124 | "paddingBottom": 0.0,
125 | "text": "Item 5",
126 | "textColor": "#8a000000",
127 | "textSize": 14.0
128 | },
129 | {
130 | "left": 0.0,
131 | "top": 246.0,
132 | "right": 6.0,
133 | "bottom": 287.0,
134 | "type": "android.widget.TextView",
135 | "enabled": true,
136 | "clickable": false,
137 | "id": "No id",
138 | "visibility": "VISIBLE",
139 | "background": "null",
140 | "paddingStart": 0.0,
141 | "paddingTop": 0.0,
142 | "paddingEnd": 0.0,
143 | "paddingBottom": 0.0,
144 | "text": "Item 6",
145 | "textColor": "#8a000000",
146 | "textSize": 14.0
147 | },
148 | {
149 | "left": 0.0,
150 | "top": 287.0,
151 | "right": 6.0,
152 | "bottom": 328.0,
153 | "type": "android.widget.TextView",
154 | "enabled": true,
155 | "clickable": false,
156 | "id": "No id",
157 | "visibility": "VISIBLE",
158 | "background": "null",
159 | "paddingStart": 0.0,
160 | "paddingTop": 0.0,
161 | "paddingEnd": 0.0,
162 | "paddingBottom": 0.0,
163 | "text": "Item 7",
164 | "textColor": "#8a000000",
165 | "textSize": 14.0
166 | }
167 | ]
168 | }
169 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/layoutSnapshots/schema_v3_features.json:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 3,
3 | "features": {
4 | "left": 0.0,
5 | "top": 0.0,
6 | "right": 600.0,
7 | "bottom": 800.0,
8 | "type": "android.widget.LinearLayout",
9 | "enabled": true,
10 | "clickable": false,
11 | "id": "No id",
12 | "visibility": "VISIBLE",
13 | "background": "null",
14 | "children": [
15 | {
16 | "left": 0.0,
17 | "top": 0.0,
18 | "right": 42.0,
19 | "bottom": 73.0,
20 | "type": "android.widget.TextView",
21 | "enabled": true,
22 | "clickable": false,
23 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_a",
24 | "visibility": "VISIBLE",
25 | "background": "#ffff0000",
26 | "paddingStart": 16.0,
27 | "paddingTop": 16.0,
28 | "paddingEnd": 16.0,
29 | "paddingBottom": 16.0,
30 | "text": "TextView A",
31 | "textColor": "#8a000000",
32 | "textSize": 14.0
33 | },
34 | {
35 | "left": 0.0,
36 | "top": 0.0,
37 | "right": 0.0,
38 | "bottom": 0.0,
39 | "type": "android.widget.TextView",
40 | "enabled": true,
41 | "clickable": false,
42 | "id": "com.redapparat.layoutverifier.tests.test:id/textView_b",
43 | "visibility": "GONE",
44 | "background": "Drawable",
45 | "paddingStart": 0.0,
46 | "paddingTop": 0.0,
47 | "paddingEnd": 0.0,
48 | "paddingBottom": 0.0,
49 | "text": "TextView B",
50 | "textColor": "#8a000000",
51 | "textSize": 14.0
52 | }
53 | ]
54 | }
55 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_001.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_002.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_003.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_004.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_005.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_006.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_007.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_008.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_009.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
19 |
20 |
25 |
26 |
27 |
31 |
32 |
38 |
39 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_014.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
24 |
25 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/main/res/layout/case_015.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
--------------------------------------------------------------------------------
/layoutverifier-tests/src/test/java/com/redapparat/layoutverifier/tests/LayoutVerifierIntegrationTests.kt:
--------------------------------------------------------------------------------
1 | package com.redapparat.layoutverifier.tests
2 |
3 | import android.view.View
4 | import androidx.recyclerview.widget.LinearLayoutManager
5 | import androidx.recyclerview.widget.RecyclerView
6 | import androidx.test.core.app.ApplicationProvider.getApplicationContext
7 | import androidx.test.ext.junit.runners.AndroidJUnit4
8 | import com.redapparat.layoutverifier.LayoutVerifier
9 | import com.redapparat.layoutverifier.Schemas
10 | import com.redapparat.layoutverifier.extractor.DefaultFeatures
11 | import com.redapparat.layoutverifier.serializer.GsonSerializer
12 | import com.redapparat.layoutverifier.tests.view.SimpleAdapter
13 | import org.junit.After
14 | import org.junit.Assert.*
15 | import org.junit.Test
16 | import org.junit.runner.RunWith
17 | import java.io.File
18 |
19 |
20 | @RunWith(AndroidJUnit4::class)
21 | class LayoutVerifierIntegrationTests {
22 |
23 | @Test
24 | fun `Case 1 - Flat layout - Success`() {
25 | defaultLayoutVerifier()
26 | .layout(R.layout.case_001)
27 | .match("flat_layout")
28 | }
29 |
30 | @Test
31 | fun `Case 2 - Flat layout - Failure, layout structure is different`() {
32 | assertException(AssertionError::class.java) {
33 | defaultLayoutVerifier()
34 | .layout(R.layout.case_002)
35 | .match("flat_layout")
36 | }
37 | }
38 |
39 | @Test
40 | fun `Case 3 - Flat layout - Failure, content is different`() {
41 | assertException(AssertionError::class.java) {
42 | defaultLayoutVerifier()
43 | .layout(R.layout.case_003)
44 | .match("flat_layout")
45 | }
46 | }
47 |
48 | @Test
49 | fun `Case 4 - Flat layout - Success, different layout type but same output`() {
50 | defaultLayoutVerifier()
51 | .layout(R.layout.case_004)
52 | .match("flat_layout")
53 | }
54 |
55 | @Test
56 | fun `Case 5 - Flat layout - Failure, different layout with strict type matching`() {
57 | assertException(AssertionError::class.java) {
58 | defaultLayoutVerifier()
59 | .layout(R.layout.case_005)
60 | .matchType(true)
61 | .match("flat_layout")
62 | }
63 | }
64 |
65 | @Test
66 | fun `Case 6 - Flat layout - Success, only match given views`() {
67 | defaultLayoutVerifier()
68 | .layout(R.layout.case_006)
69 | .views(R.id.textView_b)
70 | .match("flat_layout__view_subset")
71 | }
72 |
73 | @Test
74 | fun `Case 7 - Flat layout - Success, ignore text`() {
75 | defaultLayoutVerifier()
76 | .layout(R.layout.case_007)
77 | .excludeFeatures(setOf(DefaultFeatures.TEXT))
78 | .match("flat_layout")
79 | }
80 |
81 | @Test
82 | fun `Case 8 - Flat layout - Small screen`() {
83 | defaultLayoutVerifier()
84 | .layout(R.layout.case_008)
85 | .screenSize(100, 100)
86 | .match("flat_layout__small_screen")
87 | }
88 |
89 | @Test
90 | fun `Case 9 - Nested layout - Success`() {
91 | defaultLayoutVerifier()
92 | .layout(R.layout.case_009)
93 | .match("nested_layout")
94 | }
95 |
96 | @Test
97 | fun `Case 10 - Recycler view - Success, content fits on the screen`() {
98 | val recyclerView = RecyclerView(getApplicationContext())
99 | recyclerView.layoutManager = LinearLayoutManager(getApplicationContext())
100 | recyclerView.adapter = SimpleAdapter(3)
101 |
102 | defaultLayoutVerifier()
103 | .view(recyclerView)
104 | .match("recycler_view__3_elements")
105 | }
106 |
107 | @Test
108 | fun `Case 11 - Recycler view - Success, content does not fit on the screen`() {
109 | val recyclerView = RecyclerView(getApplicationContext())
110 | recyclerView.layoutManager = LinearLayoutManager(getApplicationContext())
111 | recyclerView.adapter = SimpleAdapter(50)
112 |
113 | defaultLayoutVerifier()
114 | .view(recyclerView)
115 | .screenSize(240, 320)
116 | .match("recycler_view__50_elements")
117 | }
118 |
119 | @Test
120 | fun `Case 12 - Schema version is the same - Do not rewrite snapshot file`() {
121 | // Cleanup
122 | val snapshotFile = File(
123 | LayoutVerifier.DEFAULT_SNAPSHOTS_PATH,
124 | "schema_version_idempotency.json"
125 | )
126 |
127 | // Run test once
128 | defaultLayoutVerifier()
129 | .layout(R.layout.case_001)
130 | .match("schema_version_idempotency")
131 |
132 | // Ensure file exists
133 | assertTrue("Snapshot file exists", snapshotFile.exists())
134 |
135 | // Read snapshot for the first run
136 | val snapshotOnFirstRun = GsonSerializer().deserializeFromStream(snapshotFile.inputStream())
137 |
138 | // Run test second time which will result in a different snapshot file
139 | defaultLayoutVerifier()
140 | .layout(R.layout.case_007)
141 | .excludeFeatures(setOf(DefaultFeatures.TEXT))
142 | .match("schema_version_idempotency")
143 |
144 | // Read snapshot for the second run
145 | val snapshotOnSecondRun = GsonSerializer().deserializeFromStream(snapshotFile.inputStream())
146 |
147 | // Two runs should given an identical snapshot since the second run would not overwrite the
148 | // file
149 | assertEquals(
150 | snapshotOnFirstRun,
151 | snapshotOnSecondRun
152 | )
153 | }
154 |
155 | @Test
156 | fun `Case 13 - Schema version changed - Success, layout is valid in old schema`() {
157 | // Run test on old schema
158 | LayoutVerifier.Builder(getApplicationContext())
159 | .schemaVersion(1)
160 | .build()
161 | .layout(R.layout.case_001)
162 | .match("schema_update_success")
163 |
164 | // Run test on new schema. Should succeed.
165 | LayoutVerifier.Builder(getApplicationContext())
166 | .schemaVersion(Schemas.latestVersion)
167 | .build()
168 | .layout(R.layout.case_001)
169 | .match("schema_update_success")
170 | }
171 |
172 | @Test
173 | fun `Case 13 - Schema version changed - Failure, layout is not valid in old schema`() {
174 | // Run test on old schema
175 | LayoutVerifier.Builder(getApplicationContext())
176 | .schemaVersion(1)
177 | .build()
178 | .layout(R.layout.case_001)
179 | .match("schema_update_failure")
180 |
181 | // Run test on new schema. Should fail.
182 | assertException(AssertionError::class.java) {
183 | LayoutVerifier.Builder(getApplicationContext())
184 | .schemaVersion(Schemas.latestVersion)
185 | .build()
186 | .layout(R.layout.case_002)
187 | .match("schema_update_failure")
188 | }
189 | }
190 |
191 | @Test
192 | fun `Case 14 - Schema v3 features`() {
193 | defaultLayoutVerifier()
194 | .layout(R.layout.case_014)
195 | .match("schema_v3_features")
196 | }
197 |
198 | @Test
199 | fun `Case 15 - Russian characters`() {
200 | // Generate initial snapshot
201 | defaultLayoutVerifier()
202 | .layout(R.layout.case_015)
203 | .match("russian_characters")
204 |
205 | // Run validation against the saved snapshot
206 | defaultLayoutVerifier()
207 | .layout(R.layout.case_015)
208 | .match("russian_characters")
209 | }
210 |
211 | @Test
212 | fun `Case 16 - Generated view id`() {
213 | val view = View(getApplicationContext())
214 |
215 | view.id = View.generateViewId()
216 |
217 | defaultLayoutVerifier()
218 | .view(view)
219 | .match("generated_view_id")
220 | }
221 |
222 | @After
223 | fun deleteTemporarySnapshotFiles() {
224 | val testNames = listOf(
225 | "schema_version_idempotency",
226 | "schema_update_success",
227 | "schema_update_failure",
228 | "russian_characters"
229 | )
230 |
231 | testNames
232 | .map { File(LayoutVerifier.DEFAULT_SNAPSHOTS_PATH, "$it.json") }
233 | .forEach {
234 | if (it.exists()) {
235 | assertTrue(it.delete())
236 | }
237 | }
238 | }
239 |
240 | private fun defaultLayoutVerifier() = LayoutVerifier.Builder(getApplicationContext())
241 | .build()
242 |
243 | private fun assertException(type: Class<*>, operation: () -> Any) {
244 | try {
245 | operation()
246 | fail("Expected exception of type $type. No exception received.")
247 | } catch (e: Throwable) {
248 | if (!type.isAssignableFrom(e.javaClass)) {
249 | fail("Expected exception of type $type. Received: $e")
250 | }
251 | }
252 | }
253 |
254 | }
--------------------------------------------------------------------------------
/layoutverifier-tests/src/test/java/com/redapparat/layoutverifier/tests/view/SimpleAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.redapparat.layoutverifier.tests.view
2 |
3 | import android.content.Context
4 | import android.view.ViewGroup
5 | import android.widget.TextView
6 | import androidx.recyclerview.widget.RecyclerView
7 |
8 | class SimpleAdapter(private val size: Int) : RecyclerView.Adapter() {
9 |
10 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
11 | return ViewHolder(parent.context)
12 | }
13 |
14 | override fun getItemCount(): Int {
15 | return size
16 | }
17 |
18 | override fun onBindViewHolder(holder: ViewHolder, position: Int) {
19 | holder.bind(position)
20 | }
21 |
22 | class ViewHolder(context: Context) : RecyclerView.ViewHolder(TextView(context)) {
23 |
24 | fun bind(position: Int) {
25 | (itemView as TextView).text = "Item $position"
26 | }
27 |
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/layoutverifier/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/layoutverifier/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | group = 'com.redapparat'
6 |
7 | android {
8 | compileSdkVersion 29
9 | buildToolsVersion "29.0.3"
10 |
11 | defaultConfig {
12 | minSdkVersion 17
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 | }
17 | }
18 |
19 | dependencies {
20 | api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
21 | implementation 'androidx.appcompat:appcompat:1.1.0'
22 | api 'androidx.core:core-ktx:1.2.0'
23 | api 'com.google.code.gson:gson:2.8.6'
24 | implementation 'junit:junit:4.12'
25 |
26 | testImplementation 'junit:junit:4.12'
27 | }
28 |
29 | ext {
30 | bintrayName = 'layoutverifier'
31 |
32 | libraryName = 'LayoutVerifier'
33 | artifact = 'layoutverifier'
34 | libraryVersion = artifactVersion
35 |
36 | libraryDescription = 'Test Android layouts without device'
37 | }
38 |
39 | apply from: '../deploy.gradle'
40 |
--------------------------------------------------------------------------------
/layoutverifier/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/layoutverifier/src/main/java/com/redapparat/layoutverifier/LayoutMatcher.kt:
--------------------------------------------------------------------------------
1 | package com.redapparat.layoutverifier
2 |
3 | import android.util.TypedValue
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import androidx.annotation.IdRes
7 | import com.redapparat.layoutverifier.extractor.DefaultFeatures
8 | import org.junit.Assert.assertEquals
9 | import java.io.File
10 | import java.io.IOException
11 | import java.io.Serializable
12 |
13 | /**
14 | * Performs layout matching based for a given view.
15 | *
16 | * Provide test-specific configuration (i.e. [LayoutMatcher.screenSize]) and
17 | * call [LayoutMatcher.match].
18 | *
19 | * See [LayoutVerifier] for usage examples.
20 | */
21 | class LayoutMatcher internal constructor(
22 | private val view: View,
23 | private val configuration: LayoutVerifier.Configuration
24 | ) {
25 |
26 | private var widthPx = 600
27 | private var heightPx = 800
28 |
29 | private var viewIds: Set? = null
30 | private val excludedFeatures = mutableSetOf(
31 | DefaultFeatures.TYPE,
32 | DefaultFeatures.ID
33 | )
34 |
35 | /**
36 | * Set device screen size in pixels.
37 | */
38 | fun screenSizePx(widthPx: Int, heightPx: Int): LayoutMatcher {
39 | this.widthPx = widthPx
40 | this.heightPx = heightPx
41 |
42 | return this
43 | }
44 |
45 | /**
46 | * Set device screen size in DP.
47 | */
48 | fun screenSize(widthDp: Int, heightDp: Int): LayoutMatcher {
49 | return screenSizePx(
50 | dpToPx(widthDp.toFloat()).toInt(),
51 | dpToPx(heightDp.toFloat()).toInt()
52 | )
53 | }
54 |
55 | /**
56 | * Only match following view IDs when running test and ignore the rest.
57 | */
58 | fun views(@IdRes vararg viewIds: Int): LayoutMatcher {
59 | this.viewIds = viewIds.toSet()
60 |
61 | return this
62 | }
63 |
64 | /**
65 | * Enforce strict type matching (i.e. replacing RelativeLayout with ConstraintLayout will
66 | * cause a test failure).
67 | *
68 | * `false` by default.
69 | *
70 | * **Note**: `matchType(false)` is equivalent to `excludeFeatures(setOf(DefaultFeatures.TYPE))`.
71 | */
72 | fun matchType(match: Boolean): LayoutMatcher {
73 | if (match) {
74 | excludedFeatures.remove(DefaultFeatures.TYPE)
75 | } else {
76 | excludedFeatures.add(DefaultFeatures.TYPE)
77 | }
78 |
79 | return this
80 | }
81 |
82 | /**
83 | * Exclude features from matching process.
84 | *
85 | * Features excluded by default:
86 | * - [DefaultFeatures.TYPE]
87 | * - [DefaultFeatures.ID]
88 | */
89 | fun excludeFeatures(toExclude: Iterable): LayoutMatcher {
90 | excludedFeatures.addAll(toExclude)
91 |
92 | return this
93 | }
94 |
95 | /**
96 | * Performs matching. If no pre-recorded test results are available, succeeds the test and
97 | * writes result to a file to be used for future test runs.
98 | *
99 | * Test name must be unique within build module (i.e. gradle module).
100 | */
101 | fun match(testName: String) {
102 | prepareView(view)
103 |
104 | val features = extractFeaturesRecursively(view)
105 |
106 | val testSnapshotFile = snapshotFileForTest(testName)
107 | if (testSnapshotFile.exists()) {
108 | val snapshot = configuration.serializer.deserializeFromStream(
109 | testSnapshotFile.inputStream()
110 | )
111 |
112 | val snapshotVersionCode = (snapshot["schemaVersion"] as? Double)?.toInt() ?: 0
113 | val combinedExcludedFeatures = excludedFeatures.toMutableSet()
114 |
115 | if (snapshotVersionCode < configuration.schemaVersion) {
116 | combinedExcludedFeatures += Schemas.newlyAddedFeatures(snapshotVersionCode)
117 | }
118 |
119 | val snapshotFeatures = readFeaturesFromSnapshot(snapshot)
120 |
121 | val expected = snapshotFeatures.excludeFeaturesRecursively(combinedExcludedFeatures)
122 | val actual = features.excludeFeaturesRecursively(combinedExcludedFeatures)
123 |
124 | if (expected != actual) {
125 | assertEquals(
126 | configuration.serializer.toPrettyJson(expected),
127 | configuration.serializer.toPrettyJson(actual)
128 | )
129 | } else {
130 | if (snapshotVersionCode < configuration.schemaVersion) {
131 | saveSnapshot(features, testSnapshotFile)
132 | }
133 | }
134 | } else {
135 | saveSnapshot(features, testSnapshotFile)
136 | }
137 | }
138 |
139 | private fun saveSnapshot(
140 | features: Map,
141 | testSnapshotFile: File
142 | ) {
143 | ensureSnapshotsDirectoryExists()
144 |
145 | val featuresPayload = mapOf(
146 | "schemaVersion" to configuration.schemaVersion,
147 | "features" to features
148 | )
149 |
150 | configuration.serializer.serializeToStream(
151 | featuresPayload,
152 | testSnapshotFile.outputStream()
153 | )
154 | }
155 |
156 | @Suppress("UNCHECKED_CAST")
157 | private fun readFeaturesFromSnapshot(snapshot: Map) =
158 | snapshot["features"] as? Map ?: snapshot
159 |
160 | private fun ensureSnapshotsDirectoryExists() {
161 | if (configuration.snapshotsDirectory.exists()) {
162 | return
163 | }
164 |
165 | if (configuration.snapshotsDirectory.mkdirs()) {
166 | return
167 | }
168 |
169 | throw IOException("Unable to create snapshots directory: ${configuration.snapshotsDirectory}")
170 | }
171 |
172 | private fun snapshotFileForTest(testName: String): File {
173 | return File(
174 | configuration.snapshotsDirectory,
175 | "$testName.json"
176 | )
177 | }
178 |
179 | private fun prepareView(view: View) {
180 | view.measure(
181 | View.MeasureSpec.makeMeasureSpec(widthPx, View.MeasureSpec.EXACTLY),
182 | View.MeasureSpec.makeMeasureSpec(heightPx, View.MeasureSpec.EXACTLY)
183 | )
184 | view.layout(0, 0, widthPx, heightPx)
185 | }
186 |
187 | private fun extractFeaturesRecursively(view: View): Map {
188 | val viewFeatures = if (filterView(view)) {
189 | configuration.featureExtractor.extractFeatures(view)
190 | } else {
191 | emptyMap()
192 | }
193 |
194 | if (view !is ViewGroup) {
195 | return viewFeatures
196 | }
197 |
198 | val childrenFeatures = arrayListOf