@@ -221,3 +221,121 @@ TEST_F(CoreMLBackendOptionsTest, IntegrationWithOptionsMapCacheDir) {
221221 }
222222 EXPECT_TRUE (found_cache_dir) << " cache_dir option not found" ;
223223}
224+
225+ // Test setUseNewCache with true
226+ TEST_F (CoreMLBackendOptionsTest, SetUseNewCacheTrue) {
227+ LoadOptionsBuilder builder;
228+ builder.setUseNewCache (true );
229+
230+ auto options = builder.view ();
231+ EXPECT_EQ (options.size (), 1 );
232+ EXPECT_STREQ (options[0 ].key , " _use_new_cache" );
233+
234+ if (auto * val = std::get_if<bool >(&options[0 ].value )) {
235+ EXPECT_TRUE (*val);
236+ } else {
237+ FAIL () << " Expected bool value for _use_new_cache" ;
238+ }
239+ }
240+
241+ // Test setUseNewCache with false
242+ TEST_F (CoreMLBackendOptionsTest, SetUseNewCacheFalse) {
243+ LoadOptionsBuilder builder;
244+ builder.setUseNewCache (false );
245+
246+ auto options = builder.view ();
247+ EXPECT_EQ (options.size (), 1 );
248+ EXPECT_STREQ (options[0 ].key , " _use_new_cache" );
249+
250+ if (auto * val = std::get_if<bool >(&options[0 ].value )) {
251+ EXPECT_FALSE (*val);
252+ } else {
253+ FAIL () << " Expected bool value for _use_new_cache" ;
254+ }
255+ }
256+
257+ // Test setUseNewCache method chaining
258+ TEST_F (CoreMLBackendOptionsTest, SetUseNewCacheChaining) {
259+ LoadOptionsBuilder builder;
260+ auto & result = builder.setUseNewCache (true );
261+
262+ // Should return reference to the same builder
263+ EXPECT_EQ (&result, &builder);
264+ }
265+
266+ // Test combining setComputeUnit, setCacheDirectory, and setUseNewCache
267+ TEST_F (CoreMLBackendOptionsTest, AllOptionsCombined) {
268+ LoadOptionsBuilder builder;
269+ builder.setComputeUnit (LoadOptionsBuilder::ComputeUnit::CPU_AND_GPU)
270+ .setCacheDirectory (" /path/to/cache" )
271+ .setUseNewCache (true );
272+
273+ auto options = builder.view ();
274+ EXPECT_EQ (options.size (), 3 );
275+
276+ // Find and verify each option
277+ bool found_compute_unit = false ;
278+ bool found_cache_dir = false ;
279+ bool found_use_new_cache = false ;
280+
281+ for (size_t i = 0 ; i < options.size (); ++i) {
282+ if (std::strcmp (options[i].key , " compute_unit" ) == 0 ) {
283+ found_compute_unit = true ;
284+ if (auto * arr = std::get_if<std::array<char , kMaxOptionValueLength >>(&options[i].value )) {
285+ EXPECT_STREQ (arr->data (), " cpu_and_gpu" );
286+ }
287+ } else if (std::strcmp (options[i].key , " cache_dir" ) == 0 ) {
288+ found_cache_dir = true ;
289+ if (auto * arr = std::get_if<std::array<char , kMaxOptionValueLength >>(&options[i].value )) {
290+ EXPECT_STREQ (arr->data (), " /path/to/cache" );
291+ }
292+ } else if (std::strcmp (options[i].key , " _use_new_cache" ) == 0 ) {
293+ found_use_new_cache = true ;
294+ if (auto * val = std::get_if<bool >(&options[i].value )) {
295+ EXPECT_TRUE (*val);
296+ }
297+ }
298+ }
299+
300+ EXPECT_TRUE (found_compute_unit) << " compute_unit option not found" ;
301+ EXPECT_TRUE (found_cache_dir) << " cache_dir option not found" ;
302+ EXPECT_TRUE (found_use_new_cache) << " _use_new_cache option not found" ;
303+ }
304+
305+ // Test integration with LoadBackendOptionsMap including _use_new_cache
306+ TEST_F (CoreMLBackendOptionsTest, IntegrationWithOptionsMapUseNewCache) {
307+ LoadOptionsBuilder coreml_opts;
308+ coreml_opts.setUseNewCache (true );
309+
310+ LoadBackendOptionsMap map;
311+ EXPECT_EQ (map.set_options (coreml_opts), Error::Ok);
312+
313+ EXPECT_EQ (map.size (), 1 );
314+ EXPECT_TRUE (map.has_options (" CoreMLBackend" ));
315+
316+ auto retrieved = map.get_options (" CoreMLBackend" );
317+ EXPECT_EQ (retrieved.size (), 1 );
318+ EXPECT_STREQ (retrieved[0 ].key , " _use_new_cache" );
319+
320+ if (auto * val = std::get_if<bool >(&retrieved[0 ].value )) {
321+ EXPECT_TRUE (*val);
322+ } else {
323+ FAIL () << " Expected bool value for _use_new_cache" ;
324+ }
325+ }
326+
327+ // Test setUseNewCache updates when called multiple times
328+ TEST_F (CoreMLBackendOptionsTest, SetUseNewCacheMultipleTimes) {
329+ LoadOptionsBuilder builder;
330+ builder.setUseNewCache (true );
331+ builder.setUseNewCache (false );
332+
333+ auto options = builder.view ();
334+ EXPECT_EQ (options.size (), 1 );
335+
336+ if (auto * val = std::get_if<bool >(&options[0 ].value )) {
337+ EXPECT_FALSE (*val); // Last value wins
338+ } else {
339+ FAIL () << " Expected bool value for _use_new_cache" ;
340+ }
341+ }
0 commit comments