## Copyright (c) 2021, NVIDIA CORPORATION.  All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto.  Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
from omni.ui.tests.test_base import OmniUiTest
from pathlib import Path
from pxr import Usd
from pxr import UsdGeom
import carb
import omni.client
import omni.kit
import omni.usd
import os
import time
import unittest
from omni.kit.usdz_export import usdz_export

OMNI_SERVER = "omniverse://ov-test"

class TestUsdzExport(OmniUiTest):

    def get_test_dir(self):
        token = carb.tokens.get_tokens_interface()
        data_dir = token.resolve("${data}")

        return f"{data_dir}"

    async def test_export_usdz_file(self):
        usdz_size = 2600000
        usdz_size_tc = 2675966

        current_path = Path(__file__)
        test_data_path = current_path.parent.parent.parent.parent.parent.joinpath("data")
        test_stage_path = str(test_data_path.joinpath("test_stage").joinpath("scene.usd"))
        test_dir = self.get_test_dir()
        export_file_path = Path(test_dir).joinpath("out.usdz").resolve()
        await usdz_export(test_stage_path, export_file_path.__str__())
        self.assertTrue(os.path.isfile(export_file_path.__str__()), 'out.usdz does not exist')
        size = os.stat(export_file_path).st_size
        self.assertTrue(size >= usdz_size and size <= usdz_size_tc, f'File size mismatch, expected {usdz_size} but got {size}')
