<commit_before>/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *
 * 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.
 *
 */

#include <iostream>
#include <stdlib.h>
#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/dali-toolkit.h>

using namespace Dali;
using namespace Toolkit;

void dali_tableview_startup(void)
{
  test_return_value = TET_UNDEF;
}

void dali_tableview_cleanup(void)
{
  test_return_value = TET_PASS;
}

namespace
{

const char* const PROPERTY_NAME_ROWS = "rows";
const char* const PROPERTY_NAME_COLUMNS = "columns";
const char* const PROPERTY_NAME_CELL_PADDING = "cell-padding";
const char* const PROPERTY_NAME_LAYOUT_ROWS = "layout-rows";
const char* const PROPERTY_NAME_LAYOUT_COLUMNS = "layout-columns";

static bool gObjectCreatedCallBackCalled;

static void TestCallback(BaseHandle handle)
{
  gObjectCreatedCallBackCalled = true;
}

struct Constraint100
{
  Constraint100( )
  {
  }

  /**
   * function operator to apply the parent size
   */
  void operator()( Dali::Vector3& current, const PropertyInputContainer& /* inputs */ )
  {
    current.x = current.y = current.z = 100.0f;
  }
};

// Convenience function to quickly set up a 10x10 table with each cell being 10x10 pixels in size by default.
static void SetupTableViewAndActors(TableView& tableView, Actor& actor1, Actor& actor2, Actor& actor3)
{
  tableView = TableView::New( 10, 10 ); // 10 by 10 grid.
  DALI_TEST_CHECK( tableView );

  Stage::GetCurrent().Add( tableView );
  tableView.SetSize( Dali::Vector2( 100.0f, 100.0f ) );

  actor1 = Actor::New();
  actor2 = Actor::New();
  actor3 = Actor::New();

  actor1.SetSize( Dali::Vector2( 10, 10 ) );
  actor2.SetSize( Dali::Vector2( 10, 10 ) );
  actor3.SetSize( Dali::Vector2( 10, 10 ) );

  tableView.AddChild( actor1, TableView::CellPosition( 0, 0 ) );
  tableView.AddChild( actor2, TableView::CellPosition( 0, 1 ) );
  tableView.AddChild( actor3, TableView::CellPosition( 1, 0 ) );
}

} // namespace

int UtcDaliTableViewNew(void)
{
  ToolkitTestApplication application;

  TableView tableView = TableView::New(10,10);
  DALI_TEST_CHECK(tableView);

  //Additional check to ensure object is created by checking if it's registered
  ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
  DALI_TEST_CHECK( registry );

  gObjectCreatedCallBackCalled = false;
  registry.ObjectCreatedSignal().Connect(&TestCallback);
  {
    TableView tableView = TableView::New(10,10);
  }
  DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
  END_TEST;
}

// Test adjusting the metric values for the cell.
int UtcDaliTableViewMetricsPadding(void)
{
  ToolkitTestApplication application;

  tet_infoline("UtcDaliTableViewMetricsPadding");

  TableView tableView;
  Actor actor1;
  Actor actor2;
  Actor actor3;

  SetupTableViewAndActors(tableView, actor1, actor2, actor3);

  // 1. check that padding works. no padding:
  tableView.SetCellPadding(Size(0.0f, 0.0f));
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );

  // 1. check that padding works. some padding:
  tableView.SetCellPadding(Size(5.0f, 10.0f));
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(5.0f, 10.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(5.0f, 10.0f, 0.0f), TEST_LOCATION );
  END_TEST;
}

// Test adjusting the metric values for the cell.<commit_msg>Update TableView utc<commit_after>/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *
 * 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.
 *
 */

#include <iostream>
#include <stdlib.h>
#include <dali-toolkit-test-suite-utils.h>
#include <dali-toolkit/dali-toolkit.h>

using namespace Dali;
using namespace Toolkit;

void dali_tableview_startup(void)
{
  test_return_value = TET_UNDEF;
}

void dali_tableview_cleanup(void)
{
  test_return_value = TET_PASS;
}

namespace
{

const char* const PROPERTY_NAME_ROWS = "rows";
const char* const PROPERTY_NAME_COLUMNS = "columns";
const char* const PROPERTY_NAME_CELL_PADDING = "cell-padding";
const char* const PROPERTY_NAME_LAYOUT_ROWS = "layout-rows";
const char* const PROPERTY_NAME_LAYOUT_COLUMNS = "layout-columns";
const Vector2 CELL_SIZE( 10, 10 );

static bool gObjectCreatedCallBackCalled;

static void TestCallback(BaseHandle handle)
{
  gObjectCreatedCallBackCalled = true;
}

struct Constraint100
{
  Constraint100( )
  {
  }

  /**
   * function operator to apply the parent size
   */
  void operator()( Dali::Vector3& current, const PropertyInputContainer& /* inputs */ )
  {
    current.x = current.y = current.z = 100.0f;
  }
};

// Convenience function to quickly set up a 10x10 table with each cell being 10x10 pixels in size by default.
static void SetupTableViewAndActors(TableView& tableView, Actor& actor1, Actor& actor2, Actor& actor3)
{
  tableView = TableView::New( 10, 10 ); // 10 by 10 grid.
  DALI_TEST_CHECK( tableView );

  Stage::GetCurrent().Add( tableView );
  tableView.SetSize( Dali::Vector2( 100.0f, 100.0f ) );

  actor1 = Actor::New();
  actor2 = Actor::New();
  actor3 = Actor::New();

  actor1.SetSize( CELL_SIZE );
  actor2.SetSize( CELL_SIZE );
  actor3.SetSize( CELL_SIZE );

  tableView.AddChild( actor1, TableView::CellPosition( 0, 0 ) );
  tableView.AddChild( actor2, TableView::CellPosition( 0, 1 ) );
  tableView.AddChild( actor3, TableView::CellPosition( 1, 0 ) );
}

} // namespace

int UtcDaliTableViewCtorCopyP(void)
{
  TestApplication application;

  TableView actor1 = TableView::New(10,10);
  TableView actor2( actor1 );

  DALI_TEST_EQUALS( actor1, actor2, TEST_LOCATION );
  END_TEST;
}

int UtcDaliTableViewNew(void)
{
  ToolkitTestApplication application;

  TableView tableView = TableView::New(10,10);
  DALI_TEST_CHECK(tableView);

  //Additional check to ensure object is created by checking if it's registered
  ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
  DALI_TEST_CHECK( registry );

  gObjectCreatedCallBackCalled = false;
  registry.ObjectCreatedSignal().Connect(&TestCallback);
  {
    TableView tableView = TableView::New(10,10);
  }
  DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
  END_TEST;
}

// Test adjusting the metric values for the cell.
int UtcDaliTableViewMetricsPadding(void)
{
  ToolkitTestApplication application;

  tet_infoline("UtcDaliTableViewMetricsPadding");

  TableView tableView;
  Actor actor1;
  Actor actor2;
  Actor actor3;

  SetupTableViewAndActors(tableView, actor1, actor2, actor3);

  // 1. check that padding works. no padding:
  tableView.SetCellPadding(Size(0.0f, 0.0f));
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );

  // 1. check that padding works. some padding:
  tableView.SetCellPadding(Size(5.0f, 10.0f));
  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( tableView.GetCellPadding(), Size(5.0f, 10.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(5.0f, 10.0f, 0.0f), TEST_LOCATION );
  END_TEST;
}

// Test adjusting the metric values for the cell.
int UtcDaliTableViewMetricsFit(void)
{
  ToolkitTestApplication application;

  tet_infoline("UtcDaliTableViewMetricsFit");

  TableView tableView;
  Actor actor1;
  Actor actor2;
  Actor actor3;

  SetupTableViewAndActors(tableView, actor1, actor2, actor3);
  application.SendNotification();
  application.Render();

  // 1. check that with no fixed width/heights, actors are in default position.
  DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );

  // 2. check that with a fixed width & height, actors to the right and below are offsetted.
  tableView.SetFitHeight(0);
  tableView.SetFitWidth(0);
  DALI_TEST_EQUALS( tableView.IsFitHeight(0), true, TEST_LOCATION );
  DALI_TEST_EQUALS( tableView.IsFitWidth(0), true, TEST_LOCATION );

  application.SendNotification();
  application.Render();

  DALI_TEST_EQUALS( actor1.GetCurrentPosition(), Vector3(0.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor2.GetCurrentPosition(), Vector3(10.0f, 0.0f, 0.0f), TEST_LOCATION );
  DALI_TEST_EQUALS( actor3.GetCurrentPosition(), Vector3(0.0f, 10.0f, 0.0f), TEST_LOCATION );
  END_TEST;
}

// Test adjusting the metric values for the cell.
{'fraction_non_alphanumeric': 0.11473788328387735, 'fraction_numerical': 0.0351137487636004, 'mean_word_length': 4.847888953152111, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1458249', 'n_tokens_mistral': 3644, 'n_tokens_neox': 3425, 'n_words': 853}