mirror of
https://github.com/square/okhttp.git
synced 2026-01-12 10:23:16 +03:00
Only read hpack tests for the current draft.
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Square, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.spdy.hpackjson.Story;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Known good tests for HPACK interop.
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class HpackDecodeInteropGoodTest extends HpackDecodeTestBase {
|
||||
|
||||
// TODO: Filter on the json key for draft, which explains some of the failures.
|
||||
private static final String[] GOOD_INTEROP_TESTS = {
|
||||
"go-hpack",
|
||||
"haskell-http2-linear",
|
||||
"haskell-http2-linear-huffman",
|
||||
"haskell-http2-naive",
|
||||
"haskell-http2-naive-huffman",
|
||||
"haskell-http2-static",
|
||||
"haskell-http2-static-huffman",
|
||||
"nghttp2",
|
||||
"nghttp2-16384-4096",
|
||||
"nghttp2-change-table-size",
|
||||
"node-http2-hpack",
|
||||
};
|
||||
|
||||
public HpackDecodeInteropGoodTest(Story story) {
|
||||
super(story);
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static Collection<Story[]> createStories() throws Exception {
|
||||
return createStories(GOOD_INTEROP_TESTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoodDecoderInterop() throws Exception {
|
||||
testDecoder();
|
||||
}
|
||||
}
|
||||
@@ -16,35 +16,23 @@
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.spdy.hpackjson.Story;
|
||||
import org.junit.Ignore;
|
||||
import java.util.Collection;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Collection;
|
||||
import static com.squareup.okhttp.internal.spdy.hpackjson.HpackJsonUtil.storiesForCurrentDraft;
|
||||
|
||||
/**
|
||||
* Known bad tests for HPACK interop.
|
||||
*/
|
||||
// TODO: fix these tests (see if the input/test is legit, fix the implementation.)
|
||||
@Ignore
|
||||
@RunWith(Parameterized.class)
|
||||
public class HpackDecodeInteropBadTest extends HpackDecodeTestBase {
|
||||
public class HpackDecodeInteropTest extends HpackDecodeTestBase {
|
||||
|
||||
private static final String[] BAD_INTEROP_TESTS = {
|
||||
"hyper-hpack",
|
||||
"node-http2-protocol",
|
||||
"raw-data",
|
||||
"twitter-hpack"
|
||||
};
|
||||
|
||||
public HpackDecodeInteropBadTest(Story story) {
|
||||
public HpackDecodeInteropTest(Story story) {
|
||||
super(story);
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static Collection<Story[]> createStories() throws Exception {
|
||||
return createStories(BAD_INTEROP_TESTS);
|
||||
return createStories(storiesForCurrentDraft());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -17,26 +17,49 @@ package com.squareup.okhttp.internal.spdy.hpackjson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utilities for reading HPACK tests.
|
||||
*/
|
||||
public final class HpackJsonUtil {
|
||||
private static final int CURRENT_DRAFT = 9;
|
||||
|
||||
private static final String STORY_RESOURCE_FORMAT =
|
||||
"/hpack-test-case/%s/story_%02d.json";
|
||||
private static final String STORY_RESOURCE_FORMAT = "/hpack-test-case/%s/story_%02d.json";
|
||||
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
|
||||
private static Story readStory(InputStream jsonResource) throws Exception {
|
||||
private static Story readStory(InputStream jsonResource) throws IOException {
|
||||
return GSON.fromJson(new InputStreamReader(jsonResource, "UTF-8"), Story.class);
|
||||
}
|
||||
|
||||
/** Iterate through the hpack-test-case resources, only picking stories for the current draft. */
|
||||
public static String[] storiesForCurrentDraft() throws URISyntaxException {
|
||||
File testCaseDirectory = new File(HpackJsonUtil.class.getResource("/hpack-test-case").toURI());
|
||||
List<String> storyNames = new ArrayList<String>();
|
||||
for (File path : testCaseDirectory.listFiles()) {
|
||||
if (path.isDirectory() && Arrays.asList(path.list()).contains("story_00.json")) {
|
||||
try {
|
||||
Story firstStory = readStory(new FileInputStream(new File(path, "story_00.json")));
|
||||
if (firstStory.getDraft() == CURRENT_DRAFT) {
|
||||
storyNames.add(path.getName());
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
// Skip this path.
|
||||
}
|
||||
}
|
||||
}
|
||||
return storyNames.toArray(new String[storyNames.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads stories named "story_xx.json" from the folder provided.
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,11 @@ public class Story implements Cloneable {
|
||||
return cases;
|
||||
}
|
||||
|
||||
/** We only expect stories that match the draft we've implemented to pass. */
|
||||
public int getDraft() {
|
||||
return draft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Story clone() throws CloneNotSupportedException {
|
||||
Story story = new Story();
|
||||
|
||||
Reference in New Issue
Block a user