Add image/jpeg and image/png MIME support.

Add simple unit test runner.
This commit is contained in:
Syoyo Fujita 2016-01-02 23:37:12 +09:00
parent ed4d7ad34b
commit 620eed154b
3 changed files with 119 additions and 12 deletions

View File

@ -78,3 +78,15 @@ if (!ret) {
}
```
## Running tests.
### Setup
Python 2.6 or 2.7 required.
Git clone https://github.com/KhronosGroup/glTF to your local dir.
### Run test
After building `loader_test`, edit `test_runner.py`, then,
$ python test_runner.py

64
test_runner.py Normal file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env python
# Assume python 2.6 or 2.7
import glob
import os
import subprocess
## Simple test runner.
# -- config -----------------------
# Absolute path pointing to your cloned git repo of https://github.com/KhronosGroup/glTF/sampleModels
base_model_dir = "/Users/syoyo/work/glTF/sampleModels"
kinds = [ "glTF", "glTF-Binary", "glTF-Embedded", "glTF-MaterialsCommon"]
# ---------------------------------
failed = []
success = []
def run(filename):
print("Testing: " + filename)
cmd = ["./loader_test", filename]
try:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
except:
print "Failed to execute: ", cmd
raise
if p.returncode != 0:
failed.append(filename)
print(stdout)
print(stderr)
else:
success.append(filename)
def test():
for d in os.listdir(base_model_dir):
p = os.path.join(base_model_dir, d)
if os.path.isdir(p):
for k in kinds:
targetDir = os.path.join(p, k)
g = glob.glob(targetDir + "/*.gltf")
for gltf in g:
run(gltf)
def main():
test()
print("Success : {0}".format(len(success)))
print("Failed : {0}".format(len(failed)))
for fail in failed:
print("FAIL: " + fail)
if __name__ == '__main__':
main()

View File

@ -511,26 +511,57 @@ bool IsDataURI(const std::string &in) {
if (in.find(header) == 0) {
return true;
}
header = "data:image/png;base64,";
if (in.find(header) == 0) {
return true;
}
header = "data:image/jpeg;base64,";
if (in.find(header) == 0) {
return true;
}
return false;
}
bool DecodeDataURI(std::vector<unsigned char> &out, const std::string &in,
size_t reqBytes, bool checkSize) {
std::string header = "data:application/octet-stream;base64,";
std::string data;
if (in.find(header) == 0) {
std::string data =
base64_decode(in.substr(header.size())); // cut mime string.
if (checkSize) {
if (data.size() != reqBytes) {
return false;
}
out.resize(reqBytes);
} else {
out.resize(data.size());
}
std::copy(data.begin(), data.end(), out.begin());
return true;
data = base64_decode(in.substr(header.size())); // cut mime string.
}
if (data.empty()) {
header = "data:image/jpeg;base64,";
if (in.find(header) == 0) {
data = base64_decode(in.substr(header.size())); // cut mime string.
}
}
if (data.empty()) {
header = "data:image/png;base64,";
if (in.find(header) == 0) {
data = base64_decode(in.substr(header.size())); // cut mime string.
}
}
if (data.empty()) {
return false;
}
if (checkSize) {
if (data.size() != reqBytes) {
return false;
}
out.resize(reqBytes);
} else {
out.resize(data.size());
}
std::copy(data.begin(), data.end(), out.begin());
return true;
return false;
}