瀏覽代碼

URL test program, and glfw3 detection for darwin

pull/2/head
Odilitime 4 年之前
父節點
當前提交
83f528e6db
共有 2 個檔案被更改,包括 63 行新增3 行删除
  1. 13
    3
      Makefile
  2. 50
    0
      tests/testPrograms/URLtest.cpp

+ 13
- 3
Makefile 查看文件

@@ -13,8 +13,12 @@ MD5SUM = md5sum
ifeq ($(UNAME), Darwin)
CXXFLAGS = -O3 -std=c++1y -DVERSION=\"$(GIT_VERSION)\"
WARNINGS =
LIBS = -L/usr/local/lib -lglfw -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lGLEW -lfreetype -lharfbuzz -lmbedtls -lmbedcrypto -lmbedx509
LDFLAGS = -O3 -L /usr/local/lib
ifneq ("$(wildcard /usr/local/lib/libglfw3.a)","")
LIBS = -lglfw3 -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lGLEW -lfreetype -lharfbuzz -lmbedtls -lmbedcrypto -lmbedx509 \
else
LIBS = -lglfw3 -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -lGLEW -lfreetype -lharfbuzz -lmbedtls -lmbedcrypto -lmbedx509
endif
LDFLAGS = -O3 -L/usr/local/lib
INCPATH = -I /usr/local/include -I /usr/local/include/freetype2 -I /usr/local/include/harfbuzz
MD5SUM = md5
endif
@@ -26,7 +30,7 @@ SRCDIR = src
OBJDIR = gen
DEPDIR = d

SOURCES = $(subst ./,,$(shell find src -name *.cpp))
SOURCES = $(subst ./,,$(shell find src -name \*.cpp))
OBJECTS = $(subst $(SRCDIR),$(OBJDIR),$(SOURCES:.cpp=.o))

all: $(SOURCES) netrunner
@@ -78,6 +82,12 @@ $(OBJDIR)/%.o: $(SRCDIR)/%.cpp | shaders
$(DEPDIR)/%d: ;
.PRECIOUS: $(DEPDIR)/%.d

test-url.o: tests/testPrograms/URLtest.cpp
$(CXX) -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td $(CXXFLAGS) $(INCPATH) $(WARINGS) -c -o $@ $<

ntr-run-tests: test-url.o $(OBJDIR)/URL.o $(OBJDIR)/StringUtils.o
$(LINK) $(LDFLAGS) -o $@ test-url.o $(OBJDIR)/URL.o $(OBJDIR)/StringUtils.o $(LIBS)

clean:
-@rm -rf src/graphics/opengl/shaders/gen $(OBJDIR) $(EXECUTABLE) 2>/dev/null || true


+ 50
- 0
tests/testPrograms/URLtest.cpp 查看文件

@@ -0,0 +1,50 @@
#include <algorithm>
#include <iostream>
#include <memory>
#include <string>
#include "../../src/URL.h"

void test_parser(std::string url, std::string scheme, std::string userinfo,
std::string host, int port, std::string path, std::string query, std::string fragment) {
//std::unique_ptr<URL>
std::tuple<std::unique_ptr<URL>,enum URIParseError> result = parseUri(url);
if (std::get<1>(result) != URI_PARSE_ERROR_NONE) {
// TODO We probably wanna handle this better..
std::cerr << "error parsing uri" << std::endl;
return;
}
std::unique_ptr<URL> uri = std::move(std::get<0>(result));
if (uri->scheme == scheme && uri->userinfo == userinfo &&
uri->host == host && uri->port == port &&
uri->path == path && uri->query == query && uri->fragment == fragment) {
std::cout << "noice" << std::endl;
} else {
std::cout << "nope" << std::endl;
std::cout << uri->scheme << " vs " << scheme << std::endl;
std::cout << uri->userinfo << " vs " << userinfo << std::endl;
std::cout << uri->host << " vs " << host << std::endl;
std::cout << uri->port << " vs " << port << std::endl;
std::cout << uri->path << " vs " << path << std::endl;
std::cout << uri->query << " vs " << query << std::endl;
std::cout << uri->fragment << " vs " << fragment << std::endl;
}
}

int main(void) {
test_parser("HTTP://username:password@www.example.org:8080/", "http", "username:password", "www.example.org", 8080, "/", "", "");
test_parser("http://username:password@www.example.org:8080/", "http", "username:password", "www.example.org", 8080, "/", "", "");
test_parser("http://www.example.org:8080/", "http", "", "www.example.org", 8080, "/", "", "");
test_parser("http://www.example.org/", "http", "", "www.example.org", 80, "/", "", "");
test_parser("http://www.example.org", "http", "", "www.example.org", 80, "/", "", "");
//test_parser("http://www.example.org//", "http", "", "www.example.org", 80, "/", "", "");
test_parser("http://www.example.org/this/path", "http", "", "www.example.org", 80, "/this/path", "", "");
test_parser("http://www.example.org:/this/path", "http", "", "www.example.org", 80, "/this/path", "", "");
test_parser("http://username:password@www.example.org:/this/path", "http", "username:password", "www.example.org", 80, "/this/path", "", "");
test_parser("http://username:password@www.example.org/", "http", "username:password", "www.example.org", 80, "/", "", "");
test_parser("http://username:passwor:d@www.example.org/", "http", "username:passwor:d", "www.example.org", 80, "/", "", "");
test_parser("http://username:passwor:d@www.example.org:9090/", "http", "username:passwor:d", "www.example.org", 9090, "/", "", "");
test_parser("http://username:passwor:d@www.example.org:9090/this/path?query", "http", "username:passwor:d", "www.example.org", 9090, "/this/path", "query", "");
test_parser("http://www.example.org:9090/this/path?query", "http", "", "www.example.org", 9090, "/this/path", "query", "");
test_parser("http://www.example.org/this/path?query", "http", "", "www.example.org", 80, "/this/path", "query", "");
test_parser("http://www.example.org?query", "http", "", "www.example.org", 80, "/", "query", "");
}

Loading…
取消
儲存